Questions tagged [qabstracttablemodel]

QAbstractTableModel is a class in Qt for models that represent their data as a two-dimentional array of items.

The QAbstractTableModel class can't be used directly, but one can subclass his own class from it to represent a specific Table Model. However, the interface of this class is more specialized than QAbstractItemModel, so your derived classes can't be used in tree views.

A list of functions that need to be implemented when subclassing QAbstractTableModel includes:

  • rowCount()
  • columnCount()
  • data()
  • headerData()
  • setData()1
  • flags()1
  • insertRows()2
  • removeRows()2
  • insertColumns()2
  • removeColumns()2

1: for models that support editing.

2: for models with resizable data structure.

Official documentation is available here.

202 questions
0
votes
1 answer

Non editable cell in qtableview

I have a QTableView for a custom class inherited from QAbstractTableModel. Does someone knows a way to set a particular cell of a QTableView (or the model) as non editable according to a value from another cell of the same row of the model? Im using…
user20679
  • 442
  • 4
  • 17
0
votes
0 answers

QT QAbstractTableModel implement insertRows

I have an Impl of QAbstractTableModel, which has a vector items with all items of the table (one Item per Row) int rowCount(..){ return items.size() } QVariant data(const QModelIndex &index, int role){ Item i = items.at(index.row())); …
Tobi
  • 924
  • 1
  • 10
  • 39
0
votes
1 answer

Tooltip is not updated on moving from one row to another

I have subclassed QAbstractTableModel and in data() function I am displaying an image in last column of each row and a tooltip on mouse hover. QVariant MyTableModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return…
wazza
  • 313
  • 3
  • 19
0
votes
0 answers

Get column sum in a QAbstractTableModel

I often need to calculate the sum of all values in a table column so I can display various summaries, averages etc. Right now I'm using my own helper method: double Utils::columnSum(QAbstractTableModel *model, int columnIndex) { …
sashoalm
  • 75,001
  • 122
  • 434
  • 781
0
votes
1 answer

Qt TableView model setData() crashes application

I am learning Qt and I am developing Minesweeper alike game now. For displaying game board I am using QTableView with my custom model that extends QAbstractTableModel. Displaying data from model works well. I have overloaded QVariant data(const…
Krzysiek
  • 7,895
  • 6
  • 37
  • 38
0
votes
0 answers

how to present a user-defined widget in QTableview's cell (without using qml)

These days I encounter a problem about qt. There is a batch data which I want to show in my qt application with QTableview(not qml gridview, since my application use widgets). Each data item include a image and a image name. I need to let the image…
0
votes
1 answer

Qt - item model/view - multiple data in one cell of QTableView

I'm trying to use model/view architecture in C++ and QT and need to understand, how is the best way to divide one cell in QTableView to more rows or more columns and use different widgets for them and also how to display just some columns from the…
Nick
  • 107
  • 3
  • 11
0
votes
1 answer

Right way to inherit interface by interface

I have interface class IHistory. And i want to implement QAbstractTableModel. My code invoke undefined reference to vtable error, and it's doesn't fix by running qmake. (ihistory.h) class IHistory: public QAbstractTableModel { ... //…
murzagurskiy
  • 1,273
  • 1
  • 20
  • 44
0
votes
1 answer

Search QTableView with a value(e.g. ID) which is not displayed

Scenario: Say, I have a person class class Person{ int id; // only unique value, NOT displayed QString name; // displayed QString address; // displayed QString age; // displayed etc etc //…
Yousuf Azad
  • 414
  • 1
  • 7
  • 17
0
votes
1 answer

Set focus in a QTableView

I have a QMainWindow containing a QTableView as its centralwidget. I populate this QTableView by setting a model (which is derived from QAbstractTableModel). The selection behavior for the QTableView is set to QAbstractItemView::SelectRows. This…
Lieuwe
  • 1,734
  • 2
  • 27
  • 41
0
votes
0 answers

How to update view when model data source changes?

I have a class which inherits from QAbstractTableModel, which simply points along to a separate class for the views to access data information as follows: #include "QAbstractTableModel" class MyModel : public QAbstractTableModel { …
koolbanana
  • 719
  • 5
  • 11
0
votes
0 answers

Two QListView's and a multimensional array, one showing the array of the selected element

Having trouble with the title of the question but essentially I have a two QListView's side by side, a two dimensional array and using a TableViewModel containing that array; and now I want the QListView on the right to display the selected row's…
SuperWig
  • 155
  • 3
  • 14
0
votes
0 answers

Qt does not update several QTableView cells when editing in the code

I have a simple logic, that basically goes like this: a few entries are filtered from source model (my custom QAbstractTableModel) and presented to the user using QSortFilterProxyModel, which does have only modified filterAcceptsRow function. This…
rofl
  • 343
  • 3
  • 18
0
votes
1 answer

How to add validator on DisplayRole and EditRole in QTableView in PyQt?

I have a QTableView that populates files and folders as items using QAbstractTableModel, I didn't used QFileSystemModel because the table view doesnt solely displays folder names, it also displays attribute of files within the folder. So my question…
0
votes
2 answers

How to share same model with QTableView and QComboBox

The list: items = [['Pet', 'Dog'],['Pet', 'Cat'],['Bird','Eagle'],['Bird','Jay'],['Bird','Falcon']] is used by model that is assigned to QTableView and QComboBox. I want Combobox to only display "Pet" and "Bird" while QTableView to display: "Dog",…