Questions tagged [qabstractitemmodel]

QAbstractItemModel is a class in the Qt framework. It provides the abstract interface for item model classes.

The QAbstractItemModel class defines the standard interface that item models must use to be able to interoperate with other components in the model/view architecture. It is not supposed to be instantiated directly, but rather it should be subclassed in order to create new models.

The QAbstractItemModel class is one of the Model/View Classes and is part of Qt's model/view framework. It can be used as the underlying data model for the item view elements in QML or the item view classes in the Qt Widgets module.

When subclassing QAbstractItemModel, at the very least you must implement index(), parent(), rowCount(), columnCount(), and data(). These functions are used in all read-only models, and form the basis of editable models.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

346 questions
5
votes
1 answer

Insert and delete rows in QTreeView

Good day, I Have base model inherited from QAbstractItemModel, and some background threads which notify this model from time to time, in examples the insertions rows implemens somthing like this bool TreeModel::insertRows(int position, int rows,…
Topilski Alexandr
  • 669
  • 1
  • 12
  • 34
4
votes
1 answer

QTreeView/QAbstractItemModel subtrees in multiple columns

I'm working on a subclass of QAbstractItemModel that plugs into a QTreeView. It has a recursive Name = Value type structure - any index could have its own subtree. This is fine on the left side, because almost every tree view out there works that…
parkovski
  • 1,503
  • 10
  • 13
4
votes
1 answer

Qt: Example of QAbstractItemModel implementation using QtSql (to use with QTreeView)

I'm looking for an example implementation of QAbstractItemModel to use with QTreeView. The model should load data from QSqlQuery and should do it in a "lazy" way. In other words I only want to load records for nodes/parents that are open. And I'd…
user666491
4
votes
2 answers

QAbstractItemModel + QTreeView what could couse item to become unselectable?

I'm trying to create my own model based on QAbstractItemModel. It seems to work fine. It passes modeltest assertions. I've this strange problem when I remove a row. Removal operation works ok. But then other rows become unselectable (not all of…
user666491
4
votes
1 answer

QTreeView / QAbstractItemModel - adding items and using beginInsertRows

I'm implementing my model based on QAbstractItemModel and I'm using it with QTreeView to display hierachical data. Data are stored in sqlite table. My question is how should I call beginInsertRows when adding subnodes. Lets say I have some parent…
user666491
4
votes
1 answer

How do I keep my QAbstractTableModel in sync with my data store?

In my app, I have a class for keeping a list of items: class Database : public QObject { Q_OBJECT public: Database(QObject *parent, const QString &name); const Entry& item(int idx) const { Q_ASSERT(idx < itemCount()); return…
neuviemeporte
  • 6,310
  • 10
  • 49
  • 78
4
votes
1 answer

Why does QAbstractItemView removes elements after a MoveAction drag and drop?

I noticed in the source code of QAbstractItemView that the method void startDrag(Qt::DropActions supportedActions) calls some clearOrRemove() private after a drag whose type is MoveAction(), which removes selected items. Point is, when the drop…
Lithy
  • 817
  • 12
  • 23
4
votes
1 answer

Qt: remove model from view

We usually set view's model in Qt like this: view->setModel(model); But is there any way to remove a model from view? I mean literally leave a view empty like it was just created and there was not any model set to it yet. If you ask me a reason of…
Nikolai Shalakin
  • 1,349
  • 2
  • 13
  • 25
4
votes
1 answer

How does QAbstractItemModel Represent Tree?

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…
SixDegrees
  • 781
  • 1
  • 8
  • 19
4
votes
1 answer

QTreeView: hierarchical context for multi-level columns

I'm looking for a better way to display multi-level hierarchical data in a tree where the meaning of each column changes depending on the level in the tree. I am using QTreeView and QAbstractItemModel to display my model data. Each model row has a…
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
4
votes
1 answer

QModelIndex becomes invalid when removing rows

I'm subclassing QAbstractItemModel to display items in a QTreeView, and within this subclass (projectModel), I have a function to delete the currently-selected index in the tree view. Component is the class used to represent all the members of the…
Carlton
  • 4,217
  • 2
  • 24
  • 40
4
votes
1 answer

PyQt: QDataWidgetMapper mapping for custom property

In PyQt I want to use a QAbstractItemModel and QDataWidgetMapper to map widgets to the model data. For QLineEdit it works fine, but I want to have a mapping between a QButtonGroup (filled with several QRadioButton) and the model. Therefore I…
Stellarator
  • 123
  • 1
  • 10
4
votes
1 answer

How to plot QAbstractItemModel using QCustomPlot

Is there a direct way to pass QAbstractItemModel to QCustomPlot? Currently I am defining two QVector for Xval and yVal. When I have to plot, I update these two vectors from QAbstractItemModel to launch the plot function. Is there any way…
Schwab
  • 91
  • 1
  • 6
4
votes
1 answer

PySide Qt insert row at leaf item and update view

I have this mostly working code that enables the user to add items to a tree structure. This is working fine as long as you are not adding items to a leaf item (item with no children). If the item has no children then on the first time adding a…
Mark
  • 672
  • 1
  • 6
  • 19
4
votes
1 answer

QTreeView with custom items

I'm writing my first Qt application with PySide and am having some trouble creating a custom tree view. I'd like to list my own data in one column. Each item must have text with tooltip, different text color, different background color, icons with…
userwedi
  • 111
  • 1
  • 1
  • 4