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

How to update QAbstractTableModel and QTableView after sorting the data source?

I have a custom data structure that I want to display in a PyQt application using a QTableView. I'm using a subclass of QAbstractTableModel to communicate with the data. The data structure itself is in a separate module and knows nothing about…
Nick Ulle
  • 409
  • 5
  • 14
5
votes
1 answer

Incorrect view of custom hierarchical model when set proxy model that swap columns

I have custom hierarchical model, inherited from QAbstractModelItem. Also, I implement MySortFilterProxyModel subclassed from QSortFilterProxyModel. MySortFilterProxyModel can remove and swap columns. If first column in MySortFilterProxyModel…
typbl4
  • 141
  • 8
5
votes
3 answers

Get and set the active row in QTreeview programmatically (PyQt)

Is there a way to get and change the active row in a QTreeView (not QTreeWidget)? By active, I mean the row with the focus highlight, not the selected row. In the paint event, I can use QStyle.State_HasFocus to get the active row, but this doesn't…
D K
  • 5,530
  • 7
  • 31
  • 45
5
votes
1 answer

Qt error "persistent model indexes corrupted" why?

I've a problem with my Qt/interview application. I use QTreeView to display tree data. I implemented my own model based on QAbstractItemModel. I get a following error prior to application crash. It happens often after I add new record. Could You…
user666491
5
votes
2 answers

How do I get the column names of a QSqlTableModel?

I would like to have something like QString QSqlTableModel::getColumnName(int col).
tom
  • 53
  • 1
  • 3
5
votes
2 answers

QTreeView disable showing of root node

In my project I'm using a QTreeView in order to display a plot configuration. On top I have a root node called PlotConfig containing several plot windows. Each plot window contains several simple xy plots. So basically, I have something like…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
5
votes
1 answer

QAbstractItemModel with QtQuick: Column is always 0 in the index

I'm quite confused by QML. Since a few weeks, I try to implement a timeline for annotation stuff in videos with QML and I can't really get it worked, since I'm quite new to QML. I try to work you through my problem. This is an example, how the…
5
votes
1 answer

Speed up QSortFilterProxyModel filtering when dealing with nearly large data sets

Before, i asked a question about multiple column filtering that we need to represent rows that fit more than one filter pattern. Now when dealing with big tables (by big i mean about 200,000 rows and 4 columns) filtering get slow if we have a table…
IMAN4K
  • 1,265
  • 3
  • 24
  • 42
5
votes
1 answer

Destructor of QModelIndexList is too slow

The execution of this simple snippet: { QModelIndexList sel = ui->tableView->selectionModel()->selectedRows(0); sel.at(0).isValid(); // To prevent removing the previous line by optimization } takes more than 30 seconds when the number of…
Slavenskij
  • 611
  • 6
  • 13
5
votes
4 answers

Qt: View not updating after QAbstractItemModel::beginInsertRows/endInsertRows

I have a QAbstractItemModel derived model attached to a QTreeView I want to programatically append a single row to a node somewhere in my tree hierarchy. I have a slot which is connected to a signal from my view. The signal sends the QModelIndex of…
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
5
votes
0 answers

QSortFilterProxyModel + QAbstractItemModel modelIndex.internalPointer() cause crash

I implemented my own QAbstractItemModel in PyQt 4.8 (Python 2.7): class FriendListModel(QtCore.QAbstractItemModel): def __init__(self, groups, client): QtCore.QAbstractItemModel.__init__(self) self.root = groups self.client = client …
Dragonfire
  • 51
  • 2
5
votes
2 answers

combine QAbstractItemModels

I have a map = std::map, where myItemModel inherits QAbstractItemModel. I want now to combine all myItemModel in one single myItemModel (every other item model would be fine too). So that there is one big…
liquid.pizza
  • 505
  • 1
  • 10
  • 26
5
votes
1 answer

base class 'QAbstractListModel' has private copy constructor

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…
5
votes
4 answers

how set QCheckBox in QAbstractItemModel?

I have a model class TreeModel : public QAbstractItemModel which I populate with instances of my TreeItem excluding column==1. In column 1 I've created CheckBoxes: QVariant TreeModel::data(const QModelIndex &index, int role) const { if…
4pie0
  • 29,204
  • 9
  • 82
  • 118
5
votes
1 answer

When to emit dataChanged from a QAbstractItemModel

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…
strubbly
  • 3,347
  • 3
  • 24
  • 36
1 2
3
23 24