QModelIndex is a central class in the Qt model/view framework. It represents a (very abstract) way by which QAbstractItemViews can address cells in QAbstractItemModels. For list and table models, it conceptually reduces to just "int row" and "int row, int column", respectively.
Questions tagged [qmodelindex]
75 questions
14
votes
1 answer
How to iterate through a QStandardItemModel completely?
I have a QStandardItemModel, which I display in q QTreeView. Works fine.
To highlight relevant rows I want to highlight some of them: Therefore I have a QStringList with the names of the QStandItem* s to be highlighted.
QStringList…

Ralf Wickum
- 2,850
- 9
- 55
- 103
13
votes
2 answers
Creating a QModelIndex
I have spent the last week struggling to create a QModelIndex given a row and a column.
Alternatively, I would settle for changing the value of row() in an already existing QModelIndex.
Any help would be appreciated.
Edit:
QModelIndex nIndex =…

Metal Wing
- 1,065
- 2
- 17
- 40
11
votes
1 answer
QTableView: how do I correctly create a QModelIndex?
I'm trying to enter edit mode on a specific cell like this:
void MainWindow::on_addButton_released() {
tm->addRow();
tableView->scrollToBottom();
int ec=tm->firstWritableColumn();
int r=tm->rowCount(QModelIndex());
QModelIndex id…

Chris Camacho
- 1,164
- 1
- 9
- 31
10
votes
1 answer
Easier way to find (visual) position of QModelIndex in QTreeView
I'm interested in calculating the physical position of a node in QTreeView and can't find a way to do this (other than calculating it myself, which is cumbersome and error prone given the robustness of QTreeView).
Is there a standard way of finding…

Dan O
- 4,323
- 5
- 29
- 44
9
votes
5 answers
How to get list of visible QModelIndex in QAbstractItemView
Is there any way to get a list of currently visible items in QAbstractItemView? And, if it possible, to receive any notifications about changing of this list.
Upd:
I'm asking exactly about QAbstractItemView or QTreeView with non-plain structure, not…

Dmitry Sazonov
- 8,801
- 1
- 35
- 61
8
votes
1 answer
How to loop over QAbstractItemView indexes?
I want to fire QAbstractItemView::doubleClicked slot programaticaly for an item that has specific text. I want to do this using QAbstractItemView class and not it's implementations if possible.
This task boils down to looping over items and…

Tomáš Zato
- 50,171
- 52
- 268
- 778
7
votes
2 answers
How to associate QModelIndex with a new row?
I've cooked up a QAbstractListModel whose model indexes contain a pointer I absolutely needed in order to process data. I add the data like so:
void PointListModel::addPoint(int frameNumber, QPoint const& pos)
{
PointItem *pointItem = new…

Dany Joumaa
- 2,030
- 6
- 30
- 45
6
votes
3 answers
Converting QModelIndex to QString
Is there a way to convert QModelIndex to QString? The main goal behind this is that I want to work with the contents of dynamically generated QListView-Items.
QFileSystemModel *foolist = new QFileSystemModel;
…

NHI7864
- 65
- 1
- 1
- 5
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
0 answers
How should we create parent QModelIndex while calling beginInsertRows(parent, first, last)?
It is more concrete version of this question.
I want to report to the view that I'm going to insert some rows to my model. There are two ways to call beginInsertRows:
beginInsertRows(QModelIndex(), first, last)
and…

Kakadu
- 2,837
- 19
- 29
5
votes
2 answers
QAbstractTableModel: index() vs. createIndex()
When subclassing QAbstractTableModel, what's the proper way to get a QModelIndex for a given row and column (for example, to provide a convenience method data(int row, int column))?
There's index() and createIndex() - they both seem to do…

basic6
- 3,643
- 3
- 42
- 47
4
votes
1 answer
QML: How to get the QModelIndex in a delegate inside a TreeView
I have a delegate in a qml TreeView. I would like to get its QModelIndex. Vía
model.index
I only get the number of the row, where the delegate is. However, I need to pass a QModelIndex to the c++ side (to make a QPersistentModelIndex and store it…

maxwell
- 357
- 4
- 14
4
votes
1 answer
C++ model for QML TreeView
Due to lack of any other Qt demo, I am making use of Qt widgets's SimpleTreeModeldemo to implement C++ model for my QML TreeView. I have defined roles so QML can use it but I am having trouble connecting them with actual model data.
What I also…

zar
- 11,361
- 14
- 96
- 178
4
votes
2 answers
QT - How to get values from a single row in QTableView
I have a QTableView with few records, a single row contains four columns.
I need to get these 4 index values (name, surname, age, username) in order to delete them in SQLite, so I need these four values to put in the deletion query. I expect to…

user1336326
- 71
- 1
- 8
3
votes
1 answer
Easier way to find visible row of a QModelIndex in a QTreeView
Is there a way to get "visual row" of a given QModelIndex?
Let's say we have a tree with some nodes expanded and some not. For example, take a partially expanded tree and click on a last item:
item1 # (visual) row 1
item2 # 2
item5 #…

Vasaka
- 1,953
- 1
- 19
- 30