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

Qt5 Is it possible to retrieve an item's checkstate from a combobox without having a pointer to the model?

I know you can do it when you have access to the QStandardItemModel but using combobox->model() returns a QAbstractItemModel which doesn't have the item(int row, int col) accessor. I've tried working with QAbstractItemModel::itemData(QModelIndex)…
Jarrod Cabalzar
  • 408
  • 1
  • 5
  • 24
0
votes
2 answers

QTableView: how to edit non-editable cells in the program?

How should this be done by using the model->setData() method call? I have derived a class called "MyStandardItemModel" from QStandardItemModel. I have made my third and fourth columns non-editable by overriding the protected virtual flags method.…
Katoch
  • 2,709
  • 9
  • 51
  • 84
0
votes
1 answer

How can I write the text of QHeaderView's section into a file?

I'm trying to write an exporter, which takes in a QTableView and writes all its data into a .csv-file, so it can be viewed in MS Excel. Now I can't seem to find a way to read the text from the horizontal header's sections. There doesn't seem to be…
LarissaGodzilla
  • 620
  • 2
  • 10
  • 21
0
votes
1 answer

Strange interaction of QAbstractItemModel with QSortFilterProxyModel

What is wrong with this an interaction of QAbstractItemModel with QSortFilterProxyModel? On left part of screen I connected my implementation of QAbstractItemModel and on right part part I did QSortFilterProxyModel. UPD: upload the code:…
0
votes
1 answer

implement QAbstractItemModel with multi-columns tree view

i'm trying to implement QAbstractItemModel for multi columns tree view each column is a qstring but there is no data come up in the GUI till now and dont know why , help plz #ifndef PACKETLISTMODEL_H #define PACKETLISTMODEL_H #include…
0
votes
1 answer

When subclassing QAbstractItemModel, nothing shown in QTreeView

I am trying to use simple tree model, but I am not able to make the example works in my project. First, I was able to use QTreeView without problem, with QStandardItemModel. In the following case, I am able to see my QTreeView with data inside. …
peterphonic
  • 951
  • 1
  • 19
  • 38
0
votes
1 answer

QTextEdit And QPushButton in one QAbstractModelItem

I use a QTreeView to visualize my objects properties. Its something like the Property Editor in the Qt Designer. I have every kind of values, bool, text, color values, enum, float, int, filenames etc. I use a coustom model for holding all the…
norca
  • 138
  • 1
  • 14
0
votes
1 answer

QTreeView insertRows via method crushs / direct call works

I have following strange problem. I've implemented a QAbstractItemModel to the point that I can insert child nodes to the tree view but something strange occurs when I try to add the nodes via the insertRows() method. First where all is…
Michael Brenndoerfer
  • 3,483
  • 2
  • 39
  • 50
0
votes
1 answer

QAbstractItemModel->setItemData returns false when inserting Qt::UserRole

I have no idea why when I try to insert Qt::UserRole into QTreeView item it returns false always but not when i enter Qt::EditRole this is the code: void TreeVieweX::insertRow(QString& slink) { QModelIndex index =…
user63898
  • 29,839
  • 85
  • 272
  • 514
0
votes
1 answer

How to manipulate a pointer to TableView model?

When it´s necessary manipulate a model of a TableView, it's necessary to get this model using the function tableView->model() . But, this returns a pointer to an QAbstractItem, and it's necessary one to a QAbstractModel. So... I convert, using a…
0
votes
1 answer

QAbstractItemModel Lazy Loading locks application

I have implemented canFetchMore, hasChildren and fetchMore in order to allow my model to be lazy loaded. It's very simple and based on QT's: http://doc.qt.io/archives/qt-4.7/itemviews-simpletreemodel.html My problem is that in my application…
dpwr
  • 2,732
  • 1
  • 23
  • 38
0
votes
0 answers

Subclassing QStandardItemModel to avoid QAbstractItemModel

I'm implementing a Model/View for a tree like structure, and I've decided to try the QStandardItemModel on which I want to wrap on it a specific class, (which I call here "appSpecificClass"). Basically, I want part of that class (like names, or…
Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121
-1
votes
1 answer

Tree selection clears when data model refresh

I have a treeview in which I have applied sorting/filtering using QSortFilterProxyModel. When I perform some action on tree item(ex. RMB action), I refresh my data model(QAbstractItemModel). I am using beginresetmodel() before refreshing my data…
-1
votes
1 answer

Qt doubleClicked event emitted twice

I have a QTableView with a QAbstractview with only one column. I assigned the double click event to the QTableView which calls a function that prints the selected value. The strange thing is that when there is only one record in the table it works…
dhirczy87
  • 33
  • 1
  • 7
-1
votes
2 answers

QTableView with QStandardItemModel: How to perform live updates during editing a cell?

Recently, I made the switch to QT. It has taken some time, but I am starting to find my way around. However, one issue remains: I want to port a program, that responds to every key press while editing a cell in a table view (QTableView with…
mvanlint
  • 61
  • 1
  • 2
1 2 3
23
24