qabstractitemmodel

pyqt: Trying to understand insertrows for QAbstractDataModel and QTreeView

主宰稳场 提交于 2019-12-05 04:54:25
I am using PyQt to manage a tree view using a QAbstractItemModel. So far I have successfully implemented it such that I can load the data, expand and collapse it, and edit values. One thing I am not able to do, however, is wrap my head around inserting and removing rows. Short version of what I am trying to do: When the user edits a particular cell, I need to actually delete the underlying item in my object hierarchy and replace it with a different one. I implement this in the setData method of my model. Since I don't completely understand what I am doing I seem to have set it up so that it

base class 'QAbstractListModel' has private copy constructor

老子叫甜甜 提交于 2019-12-04 08:38:57
I have a QT QML project. (still very small) I started by binding a listview on my UScenario model, by subclassing QAbstractListModel and it worked fined. Now, each UScenario has a list of UTask , which also have a list of UCondition (so, Utask also subclasses QAbstractListModel ). But then, QT Creator gives me an error: Core/Tasks/utask.h:6: erreur : base class 'QAbstractListModel' has private copy constructor class UTask: public QAbstractListModel ^ So I'm not sure where is my problem. I tried reading the doc about QAbstractListModel vs QAbstractItemModel , but I have no clue. I also tried to

What are the downsides of a QAbstractListModel containing objects in QML?

倖福魔咒の 提交于 2019-12-04 06:40:07
问题 Qt offers the possibility to combine C++ models with QML and suggests three approaches in the docs: QStringList QObjectList QAbstractItemModel The two former are extremely simple to use, e.g. QObjectList : // in C++ QList<QObject*> dataList; dataList.append(new DataObject("Item 1", "red")); // in QML ListView { model: dataList delegate: Text { text: name } } but they both come with a strong caveat: Note: There is no way for the view to know that the contents of a QList has changed. If the

How to access ListView's current item from qml

孤街醉人 提交于 2019-12-03 03:44:23
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 is a NoteListModel that subclasses the QAbstractListModel and contains NoteListItems. What I would like

What are the downsides of a QAbstractListModel containing objects in QML?

左心房为你撑大大i 提交于 2019-12-02 09:53:48
Qt offers the possibility to combine C++ models with QML and suggests three approaches in the docs : QStringList QObjectList QAbstractItemModel The two former are extremely simple to use, e.g. QObjectList : // in C++ QList<QObject*> dataList; dataList.append(new DataObject("Item 1", "red")); // in QML ListView { model: dataList delegate: Text { text: name } } but they both come with a strong caveat: Note: There is no way for the view to know that the contents of a QList has changed. If the QList changes, it is necessary to reset the model [...] QAbstractItemModel is difficult to use with

How to serialize a QAbstractItemModel into QDataStream?

那年仲夏 提交于 2019-12-01 18:01:41
I've set up a QAbstractItemModel and filled that with data. My QTreeView widget displays every data in that model properly. Now, I would like to store that model serialized in a binary file (and later of cource load that binary file back into a model). Is that possible? The particulars of model serialization depend somewhat on the model's implementation. Some gotchas include: Perfectly usable models might not implement insertRows / insertColumns , preferring to use custom methods instead. Models like QStandardItemModel may have underlying items of varying types. Upon deserialization, the

Qt : setData method in a QAbstractItemModel

蹲街弑〆低调 提交于 2019-12-01 17:47:52
问题 I'm new to model view and I have been following this tutorial while checking the documentation at the same time and I stumbled upon this little detail : The code of the tutorial which can be downloaded here has in the QAbstractItemModel class (here QAbstractListModel) the setData method which code is : def setData(self, index, value, role = QtCore.Qt.EditRole): if role == QtCore.Qt.EditRole: row = index.row() color = QtGui.QColor(value) if color.isValid(): self.__colors[row] = color self

Qt : setData method in a QAbstractItemModel

依然范特西╮ 提交于 2019-12-01 17:23:26
I'm new to model view and I have been following this tutorial while checking the documentation at the same time and I stumbled upon this little detail : The code of the tutorial which can be downloaded here has in the QAbstractItemModel class (here QAbstractListModel) the setData method which code is : def setData(self, index, value, role = QtCore.Qt.EditRole): if role == QtCore.Qt.EditRole: row = index.row() color = QtGui.QColor(value) if color.isValid(): self.__colors[row] = color self.dataChanged.emit(index, index) return True return False According to the explanations in the tutorial and

Understanding Qt view-model architecture: when to create and how to cleanup indexes in QAbstractItemModel implementation?

喜夏-厌秋 提交于 2019-12-01 09:27:23
I'm currently migrating my project from QTreeWidget to QtreeView , and have a lot of problems caused by poor understanding of the Qt model-view design. So far I couldn't find answers even in Qt examples. I've implemented my QAbstractItemModel . I'm returning strings to be viewed in the QTreeView through data method. Now, the underlying data will change in runtime. To handle this my model is subscribed to a notification that does emit dataChanged(index(0,0), index(rowCount() - 1, LastColumn)); . The question is: how to create and cleanup QModelIndex objects? One of the Qt examples reimplements

When to emit dataChanged from a QAbstractItemModel

女生的网名这么多〃 提交于 2019-12-01 06:46:03
In Qt, I have a model subclassing QAbstractItemModel - it's a tree displayed in a QTreeView. The model supports various forms of change which all work OK. The two of relevance are: 1) Some data in a small number of related rows changes 2) A visualisation change means that the majority of rows should change their formatting - in particular they have a change of background highlighting. Their DisplayRole data does not change. The current design deals with both of these in the same way: for every row that has any change the model emits dataChanged(start_of_row_index,end_of_row_index) . I emit the