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
4
votes
1 answer

To set widgets on children items on QTreeView

Thanks to this thread, I'm able to add widgets to 2nd or later column of QAbstractItemView (in my example QTreeView) of top level items of a view. But is it possible to add widgets to the children items? Here's what I've tried which partly went…
IsaacS
  • 3,551
  • 6
  • 39
  • 61
4
votes
1 answer

Can I use interaction with QAbstractTableModel's data in QThread?

I know that we can't use GUI-interaction in non-GUI threads (QThread). But I don't know if we can or can't interact with model (QAbstractItemModel) in threads and if True then how to do it in the right way? I honestly searched something about this…
Крайст
  • 776
  • 1
  • 9
  • 22
3
votes
1 answer

Qt QAbstractItemModel - item removal crashes

I'm writing an application using Qt classes where I have a hierarchical structure and I need to display it in a tree view (I'm using a QTreeView widget). The data itself look like this: class StatisticsEntry { // additional data management methods …
user360607
  • 363
  • 1
  • 5
  • 14
3
votes
2 answers

QAbstractItemModel testing using modeltest

I'm looking for a good tutorial on how to use modeltest to test models based on QAbstractItemModel. I don't know how to interpret debug messages that are displayed. Also I'm having trouble configuring modeltest project to work with my app in…
user666491
3
votes
1 answer

unwanted empty rows in a proxy model

I have a question regarding Qt's model/view architecture. I have implemented a class TestModel inheriting from QAbstractItemModel, with a custom method TestModel.addRevision(...) to insert new rows and TestModel.removeRevision(...) to remove rows.…
marc
  • 264
  • 1
  • 2
  • 17
3
votes
2 answers

how to implement a QAbstractItemModel for an already existing tree-like data structure without copy?

After reading the docs and examples of QAbstractItemModel and QModelIndex, I am still confused on how to properly implement the model for a QTreeView. Since I want to provide a model for an existing hierarchical data structure, I'm avoiding using…
fferri
  • 18,285
  • 5
  • 46
  • 95
3
votes
2 answers

how to show the proper number of columns in a QTreeView for a model with different hierarchical column counts

In the code example below I populate an item model with a set of top level items which contain key-value properties that I can view and edit with a QTreeView. Looking at the Qt Documentation for QAbstractItemModel::columnCount it says that this…
Vince W.
  • 3,561
  • 3
  • 31
  • 59
3
votes
1 answer

"group by" proxy model

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…
rsht
  • 1,522
  • 12
  • 27
3
votes
2 answers

How can I update a particular QAbstractListModel item?

I have derived a class FeedItemViewModel from QAbstractListModel. I have implemented a method which adds items in the list model but I do not know how too update an item which has a specific id. Here is the code: void…
Mihai
  • 389
  • 1
  • 4
  • 16
3
votes
1 answer

Qt/QML How to return QList collection from virtual data metod from QAbstractListModel

I want to summarize What to do. I have an DataObject class which have members: QString first;QString last;QList m_sublist; I am using QAbstractListModel to this. I can refer first and last to listview but I can't refer to like…
Kevin yudo
  • 233
  • 4
  • 15
3
votes
1 answer

Multiple interleaving QAbstractItemModel::beginInsertRows()/beginRemoveRows() followed by a single endInsertRow()/endRemoveRow() call?

I am developing a top/htop clone in Qt supposed to display the processes on a remote device. A fresh list of processes is transmitted every second and causes the internal QAbstractItemModel derivative representing the states in the client to update.…
momesana
  • 41
  • 5
3
votes
1 answer

QVector with initializer list fails with 3 items

In a custom item model, I want to call data changed with some given roles. With 2 items in the initializer-list, it compiles just fine: emit dataChanged(index, index, QVector{ Qt::CheckStateRole, Qt::DisplayRole }); However, when I add a third…
Nicolas Holthaus
  • 7,763
  • 4
  • 42
  • 97
3
votes
1 answer

Qt AbstractItemModel rearranging images

I want to rearrange a set of images in a qlistview. Ive looked at the examples and I just can't get this to work. When I drag an image over another Image dropomimedata() is executed however its "data->hasImage()" is always false. When I drop an…
Fundies
  • 51
  • 5
3
votes
1 answer

spanning multiple columns, using QTreeView and QAbstractItemModel

I want to make a TreeView where the top level entries span all columns (e.g. they have one row), while children span multiple columns (e.g. they have multiple rows.) I was trying to accomplish this with QTreeView.setFirstColumnSpanned. However, I…
almaghest
  • 103
  • 2
  • 6
3
votes
2 answers

QTreeView only edits in first column?

I am trying to make a simple property editor, where the property list is a nested dict and the data is displayed and edited in a QTreeView. (Before I get to my question -- if anyone already has a working implementation of this in Python 3 I'd love…