qstandarditem

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

PyQt5: Setting data for a QStandardItem

白昼怎懂夜的黑 提交于 2019-12-25 08:05:13
问题 If I construct a QStandardItem like so: item = QtGui.QStandardItem('Item Name') When this item is added to a QStandardItemModel model and is viewed in a QTreeView I get a cell that says Item Name . However, when I construct one like: item = QtGui.QStandardItem() item.setData(123) I get an an empty cell, but I can still recall the data by calling: print(item.data()) and I will get the number 123 . How can I get the number to actually display in the cell? 回答1: The argument passed to the

Adding a right-click menu for specific items in QTreeView

ⅰ亾dé卋堺 提交于 2019-12-17 21:57:55
问题 I'm writing a Qt desktop application in c++ with Qt Creator. I declared in my main window a treeView, and a compatible model. Now, I would like to have a right-click menu for the tree item. Not for all of the items, but for a part of them, for example: for the tree elements with an even index. I tried adding a simple context menu with the following code: in the .h file: QStandardItemModel* model; QMenu* contextMenu; QAction* uninstallAction; private slots: void uninstallAppletClickedSlot();

QListView item with checkbox selection behavior

回眸只為那壹抹淺笑 提交于 2019-12-06 12:35:57
问题 I'm adding checkbox items to a list view. Then when I change the check box indicator, the item row is not selected. And when I'm selection an item in the list, the check box indicator won't change. The checkbox indicator should be selected/deselected on item selection row, and checkbox indicator selection should set the item row selected. List view init: QListView *poListView = new QListView(this); // Create list view item model QStandardItemModel* poModel = new QStandardItemModel(poListView)

PyQT — How can you make a QTreeview uneditable but also selectable?

元气小坏坏 提交于 2019-12-04 22:51:23
问题 I just switched from wxPython to PyQT and I am having some trouble with the QTreeview. I have a QTreeview that will display data categorized into sections that are expandable, but the data in this TreeView should not be editable, but I need to be able to have the user select the data (doubleclicking is going to execute another method). I am not certain how to make it readonly but also selectable. I am using the QStandardItemModel with the QStandardItem to hold the data. Any help would be much