qstandarditem

QListView item with checkbox selection behavior

馋奶兔 提交于 2019-12-04 20:16:58
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); QStandardItem *poListItem = new QStandardItem; // Checkable item poListItem->setCheckable( true ); //

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

流过昼夜 提交于 2019-12-03 13:43:42
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 appreciated. You can set individual items to be uneditable by doing this when you create the

Adding a right-click menu for specific items in QTreeView

本小妞迷上赌 提交于 2019-11-28 17:30:28
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(); and in the .cpp file: in the constructor: ui->treeView->setModel(model); contextMenu = new QMenu(ui-

Preserve QStandardItem subclasses in drag and drop

天涯浪子 提交于 2019-11-28 13:06:16
I have: self.treeView = QTreeView() self.treeView.setObjectName("testView") self.treeView.setDragDropMode(QAbstractItemView.InternalMove) self.treeView.setSelectionMode(QAbstractItemView.ExtendedSelection) itemA = SubclassQStandardItemA(self) itemB = SubcalssQStandardItemB(self) self.model = QStandardItemModel() self.treeView.setModel(self.model) self.model.appendRow(itemA) self.model.appendRow(itemB) When I move itemB to itemA and check its class, ItemB is no longer a SubclassQStandardItemB but a QStandardItem. How can I keep the original class of the item when I drag and drop? ekhumoro As

Preserve QStandardItem subclasses in drag and drop

こ雲淡風輕ζ 提交于 2019-11-27 07:37:20
问题 I have: self.treeView = QTreeView() self.treeView.setObjectName("testView") self.treeView.setDragDropMode(QAbstractItemView.InternalMove) self.treeView.setSelectionMode(QAbstractItemView.ExtendedSelection) itemA = SubclassQStandardItemA(self) itemB = SubcalssQStandardItemB(self) self.model = QStandardItemModel() self.treeView.setModel(self.model) self.model.appendRow(itemA) self.model.appendRow(itemB) When I move itemB to itemA and check its class, ItemB is no longer a SubclassQStandardItemB