qabstractitemmodel

TreeView in Python+QT

家住魔仙堡 提交于 2021-02-18 08:37:28
问题 I need to make a treeView with 4 columns with a checkbox in the first column. I have made ​​the tree view, just that I do not put the checkbox in the first column. I tried but it gets me in every position (row, column ) ........... Here is my code: import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from copy import deepcopy from cPickle import dumps, load, loads from cStringIO import StringIO class myNode(object): def __init__(self, name, state, description,otro, parent=None

QTreeView QAbstractItemModel parent collapses after deleting item and sometimes crashes

南笙酒味 提交于 2021-02-11 15:26:23
问题 Im trying to build a little list of entries within a QTreeView, and based on the example posted here, I got it to delete any child items via the right click context menu i added. but when i delete it the parent tree i have collapses. And in some cases if i delete a certain item in a certain order this crashes My understanding is that this is because upon deletion the indices of the items changes, and to prevent that QtCore.QPersistentModelIndex() can be utilized according to this thread: How

QTreeView QAbstractItemModel parent collapses after deleting item and sometimes crashes

牧云@^-^@ 提交于 2021-02-11 15:25:42
问题 Im trying to build a little list of entries within a QTreeView, and based on the example posted here, I got it to delete any child items via the right click context menu i added. but when i delete it the parent tree i have collapses. And in some cases if i delete a certain item in a certain order this crashes My understanding is that this is because upon deletion the indices of the items changes, and to prevent that QtCore.QPersistentModelIndex() can be utilized according to this thread: How

How does QAbstractItemModel Represent Tree?

别等时光非礼了梦想. 提交于 2021-02-07 20:15:49
问题 I'm still having a great deal of difficulty understanding QAbstractItemModel's representation of items. There are two methods that return QModelIndex items that just aren't making any sense to me. QModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex& index) is the first. What is the view passing to this function? I index the specific tree item to have an index created for? If so, what's the point of the function? Why not just return index? What do row and column

How does QAbstractItemModel Represent Tree?

ⅰ亾dé卋堺 提交于 2021-02-07 19:59:43
问题 I'm still having a great deal of difficulty understanding QAbstractItemModel's representation of items. There are two methods that return QModelIndex items that just aren't making any sense to me. QModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex& index) is the first. What is the view passing to this function? I index the specific tree item to have an index created for? If so, what's the point of the function? Why not just return index? What do row and column

Filter model items in tree view

浪子不回头ぞ 提交于 2020-04-16 05:49:43
问题 I have a model class: class ItemModel : public QAbstractItemModel { Q_OBJECT public: enum ItemRoles { ItemRole = Qt::UserRole + 1, NameRole, IdRole, FilterRole // To be used in filtering }; QVariant data(const QModelIndex &index, int role) const; } Model returns data according to roles: QVariant ItemModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); Item *item = itemFromIndex(index); switch (role) { case ItemRole: return QVariant::fromValue(item);

Create a QModelIndex from a Data Item

試著忘記壹切 提交于 2020-01-15 23:54:09
问题 I'm looking for a way to create a QModelIndex from a particular piece of data in my model. I can go from a QModelIndex to a data item via: CustomData *data = static_cast<CustomData *>(modelIndex.internalPointer()); But I'm looking for an inverse function to go from: QModelIndex *index = createIndex(data); // ?? I've implemented linkages between my data very similar to the simple tree model example (http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html). My view displays the

How to access ListView's current item from qml

狂风中的少年 提交于 2020-01-12 03:53:45
问题 I have an application that stores and edits notes. The list of notes is displayed in a listview like this: Page { id: noteList title: i18n.tr("QNote") visible: false Column { anchors.fill: parent ListView { anchors.fill: parent model: notes delegate: ListItem.Standard { text: Title onClicked: editNote(NoteText, Title, modelData); progression: true } } } } function editNote(text, title, item) { pageStack.push(noteEdit, {title: title, text: text}); handler.setActiveItem(item); } The notes item

“group by” proxy model

北慕城南 提交于 2020-01-02 08:28:27
问题 I have tree model with theoretically infinite depth and some property "Group". In addition to standard view, I need to show this model (and keep it in sync) in such way that each group becomes a virtual parent for all items with the same property value. What is the best way to achieve this with Qt's model/view architecture? I had solved similar problem not a long time ago via inserting additional virtual "groups" on adding/removing items to/from the model, but this method proved not to be

Setting custom data for the QStringListModel item

核能气质少年 提交于 2020-01-02 05:28:29
问题 I have QStringListModel QStringListModel* blocksModel = new QStringListModel(); And a class inherited from the QObject class Block : public QObject { Q_OBJECT public: Block(); Block(const Block& other); ~Block; //and other stuff here }; Q_DECLARE_METATYPE(Block*) When I set a data for the Qt::EditRole, everything works fine but when I'm trying to set data for the Qt::UserRole, it never returns true, and when I'm getting data I see invalid QVariant int count = blocksModel->rowCount();