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
16
votes
3 answers

HowTo find Subitem in QAbstractItemModel and QTreeView class?

Question: how to find sub item, in a QTreeView loaded QAbstractItemModel model with model->match() method? Problem: model->match() can't find sub items, wtf?! Here is the example: As you can see from the picture, I'm trying to expand Layouts sub…
mosg
  • 12,041
  • 12
  • 65
  • 87
14
votes
5 answers

How to implement QML ListModel like get method for an QAbstractListModel derived model

I want to use an QAbstractListModel derived model in QML. Binding the model to views already works great. The next thing I want achieve is the ability to access specific items and their role like it is possible with a QML…
avb
  • 1,701
  • 5
  • 22
  • 37
9
votes
3 answers

How to use Model for QCombobox

I want to use QCombobox as a the Combobox of Swing in Java. So i need to use Model for holding my object. How can i hold my object in QCombobox. (I think that I should hold data in Model because QCombobox was designed according to MVC Pattern…
ibrahimyilmaz
  • 18,331
  • 13
  • 61
  • 80
9
votes
1 answer

QAbstractItemModel index() and parent() methods

It is required to implement QAbstractItemModel.parent() method or else get this nasty error: NotImplementedError: QAbstractItemModel.parent() is abstract and must be overridden Aside from .parent() the index() method also needs to be overridden or…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
9
votes
1 answer

How to access ListView's current item from qml

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 …
Peter
  • 1,047
  • 2
  • 18
  • 32
8
votes
3 answers

QAbstractItemModel data() is NEVER called

I'm attempting to create a QTreeView and use a custom model for it. I have placed qDebug() statements at various places, and I have determined that data() is never being called. How can I fix this problem? The model's code is below #include…
jecjackal
  • 1,407
  • 2
  • 20
  • 35
8
votes
1 answer

QAbstractItemModel and QTreeView

I need working examples (c++) of show own data model in QtreeView.
Dmitro
  • 1,870
  • 3
  • 16
  • 25
8
votes
2 answers

How to update QAbstractItemModel view when a Data is updated

I use the Qt example for QAbstractItemModel and I try to update an Item to a given index. I tried to use emit DataChangedbut it doesn't work, the view is not updated. Here is an example: What I want: When you click on the button, it will update Data…
Ed Nio
  • 593
  • 2
  • 11
  • 27
8
votes
2 answers

PyQt4 force view to fetchMore from QAbstractItemModel

I have a QTableView that dynamically loads data from a custom model that inherits QAbstractItemModel. The model implements both fetchMore and canFetchMore. The problem is that I would like to be able to select all rows for small datasets, but if I…
Erotemic
  • 4,806
  • 4
  • 39
  • 80
8
votes
4 answers

How to get the old value when handling QAbstractItemModel::dataChanged() signal?

I have a QTableView which have set a QStandardItemModel. The user edits data in some index in the view and then the model emits the dataChanged() signal. In the SLOT where I am handling the SIGNAL I have the QModelIndex range of the user changes and…
Uga Buga
  • 1,724
  • 3
  • 19
  • 38
8
votes
3 answers

Qt : setData method in a QAbstractItemModel

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…
Ilyes Ferchiou
  • 583
  • 3
  • 10
  • 22
8
votes
3 answers

Qt - QTreeView and custom model with checkbox columns

I wanted to have a tree view which shows the item name, the item description, and two related Boolean values in respective columns. I started by modifying the Editable Tree Mode example, so there's a TreeModel that keeps track of a group of…
Ingrid Wu
  • 81
  • 1
  • 1
  • 4
7
votes
2 answers

QAbstractListModel and QList Adapter

My application stores a few objects of a type that inherits from QAbstractListModel objects. This generates quite a lot of duplicated code when wrapping a simple std::vector or a QList into model with the general add, delete and…
pmr
  • 58,701
  • 10
  • 113
  • 156
7
votes
1 answer

pyqt: Trying to understand insertrows for QAbstractDataModel and QTreeView

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…
bvz
  • 869
  • 3
  • 13
  • 25
7
votes
3 answers

QListView with millions of items slow with keyboard

I'm using a QListView with a custom model derived from QAbstractItemModel. I have on the order of millions of items. I have called listView->setUniformItemSizes(true) to prevent a bunch of layout logic from being called when I'm adding items to the…
Matthew Kraus
  • 6,660
  • 5
  • 24
  • 31
1
2 3
23 24