qstandarditemmodel

QStandardItemModel & binding to custom object

╄→尐↘猪︶ㄣ 提交于 2020-01-24 20:49:06
问题 I tried to use the cities-standarditem of the Qt exemple and adapt it to my exemple. I have a strange result: Here is my User class: class User{ public: User(); QString getFirstname() const; void setFirstname(const QString &value); QString getLastname() const; void setLastname(const QString &value); int getAge() const; void setAge(int value); private: QString firstname; QString lastname; int age; }; and i have declared a usermodel.h: class UserModel: public QStandardItemModel { Q_OBJECT

How to iterate through a QStandardItemModel completely?

こ雲淡風輕ζ 提交于 2020-01-14 09:32:12
问题 I have a QStandardItemModel, which I display in q QTreeView. Works fine. To highlight relevant rows I want to highlight some of them: Therefore I have a QStringList with the names of the QStandItem* s to be highlighted. QStringList namesToBeHighlighted = getNames(); QModelIndex in = myModel->index(0, 0); if ( in.isValid() ) { for (int curIndex = 0; curIndex < myModel->rowCount(in); ++curIndex) { QModelIndex si = myModel->index(curIndex, 0, in); QStandardItem *curItem = myModel->itemFromIndex

QComboBox with checkboxes

给你一囗甜甜゛ 提交于 2019-12-29 07:52:07
问题 I'm creating QComboBox with checkboxes. How I can prevent collapsing of view on mouse clicking? I want to be able to set up checkboxes, but each time I click on item - drop-down of QComboBox is collapsed. Note: currently I'm debugging Qt sources and looking for workaround... 回答1: First of all you need to install an event filter to the combo box view, i.e.: combobox->view()->viewport()->installEventFilter(someobj); than you need to filter all mouse release events that happen on the combo box

Sort QStandardItemModel in c++ Qt

筅森魡賤 提交于 2019-12-23 17:09:26
问题 I have a model of type QStandardItemModel which looks like this: QHash<int, QByteArray> roleNames; roleNames[Car2goVehicle::NameRole] = "plate_number"; roleNames[Car2goVehicle::DescriptionRole] = "address"; roleNames[Car2goVehicle::FuelRole] = "fuel"; roleNames[Car2goVehicle::InteriorRole] = "interior"; roleNames[Car2goVehicle::ExteriorRole] = "exterior"; roleNames[Car2goVehicle::VinRole] = "vin"; roleNames[Car2goVehicle::LatRole] = "lat"; roleNames[Car2goVehicle::LonRole] = "lon"; roleNames

Modifying QStandardItemModel from non-UI QThread?

爱⌒轻易说出口 提交于 2019-12-22 11:46:10
问题 I have Qt4 app which binds QStandardItemModel to the QListView and have the model updated from background/non-UI thread. Sometimes, when the QStandardItem 's setText(..) method is called very repeatedly from the non-UI thread, the application will crash at a la dataChanged(..) handler. I can reproduce the issue by calling setText("xxxxx") repeatedly in a for loop. In my app, the data is read from network hence I update the model in separate, non-UI thread. Is this a common pb? If I understand

Custom QStandardItemModel with custom data method

女生的网名这么多〃 提交于 2019-12-22 11:23:07
问题 what i am trying to do is , i want to make a listView with checkable items. I was able to do it using QStandardItemModel as my model. Now what i need to do is add some features that require a custom data method . So as we would do, i sub-classed QStandardItemModel into a class and appointed it as the model, for the listView. Now the problem that i face is that , the listView is only showing text and no check option. from PyQt4.QtCore import * from PyQt4.QtGui import * import sys from random

Add items to columns in QStandardItemModel

ぐ巨炮叔叔 提交于 2019-12-19 10:14:35
问题 I am currently adding rows to my QTableView as such QStandardItem* itm; QStandardItemModel* model = new QStandardItemModel(this); model->setColumnCount(2); model->appendRow(new QStandardItem("Some Text in Column1"); How do I add items to column 2 dynamically by appending? In the above example column 2 is empty. How do I add item to column 2? 回答1: Calling appendRow(QStandardItem *) only adds a single item to the first column. You would need to pass in a QList to appendRow() to add items to

setData raises exit code -1073741819

醉酒当歌 提交于 2019-12-13 05:47:18
问题 I have a subclass of QtGui.QStandardItemModel with setData as follow: def setData(self, index, value, role): if role == QtCore.Qt.EditRole: old = self.itemFromIndex(index).text() new = value MAIN.changeItem(old,new,index) return QtGui.QStandardItemModel.setData(self, index, value, role) In MAIN.changeItem I take the 'old' value and replace it with the 'new' in the Database and and then I setData with the return value. And finally I refresh the Model to show the result. Like so: def changeItem

QTableView QStandardItemModel revert or undo user entry

不问归期 提交于 2019-12-13 04:19:48
问题 How can I undo or revert an user entry on a QTableView popuplated by QStandarItemModel? I have connected dataChanged signal with a handler where I validate the data... connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(validateData(QModelIndex,QModelIndex))); ...but in case user entry is wrong I want to revert or undo the user entry to the previous value of the item. I have read about revert() member inherited from QAbstractItemModel but I can't understand how it works

QStandardItemModel: any efficient way to add a batch of items?

故事扮演 提交于 2019-12-12 02:43:48
问题 Is there any efficient way to add a batch of QStandardItem s to a model? The model is being cleared and then I'm adding a lot of items. QtreeWidget has addTopLevelItems ( const QList<QTreeWidgetItem *> & items ) for just this, how to optimize such addition with model / view architecture? 来源: https://stackoverflow.com/questions/19694316/qstandarditemmodel-any-efficient-way-to-add-a-batch-of-items