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

How to assign QLinearGradient as QTableView items background color

Using QLineEdit's palette we can assign QGradient as its background color: line = QtGui.QLineEdit() palette = line.palette() QRectF = QtCore.QRectF(line.rect()) gradient = QtGui.QLinearGradient(QRectF.topLeft(),…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
2
votes
1 answer

How to set text to QLineEdit when it is used as QItemDelegate with QTableView

The code below creates a single QTableView. An instance of QAbstractTableModel is then created and assigned to it as its model. Lastly, the QItemDelegate is assigned to the QTableView. The column 0 is being populated with QLineEdit. While column 1…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
2
votes
2 answers

Change default selection color for QTableView

I am using a QTableView with QAbstractTableModel. I have subclassed QAbstractTableModel and in my model class for Qt::BackgroundRole and Qt::ForegroundRole I have returned some color depending on some condition. And I have subclassed QTableView…
Yousuf Azad
  • 414
  • 1
  • 7
  • 17
2
votes
1 answer

QTableView with different column width

I have a QTableView width QAbstractTableModel in the application and i want to make each column a different width, with resizing option ui->tableView->horizontalHeader()->setSectionResizeMode (QHeaderView::Stretch); In my model i do: class…
Vladislav
  • 135
  • 2
  • 11
2
votes
1 answer

sorting currency formatted numbers in QAbstractTableModel

I have a QAbstractTableModel subclass that implements data() and some of the columns are ints and doubles. I am using QLocale::toCurrencyString() and QLocale::toString() to convert those numbers based on locale to add formatting characters such as…
Alex
  • 712
  • 2
  • 13
  • 27
2
votes
2 answers

Use QAbstractTableModel implementation with a QList of custom classes

I have a general question about the implementation of the underlying data source of a QAbstractTableModel. The QAbstractTableModel::data() function access the data sources content by an index consisting of a row and a column value. If my underlying…
PSB
  • 21
  • 3
2
votes
2 answers

add a text with two different colors in a QTableView column in qt

I am using a QTableView to display user activity in my application. My model contains four columns, each column displays a different type of text like: username in the 1st column user activity in the 2nd column details of activity in the 3rd…
Sanath Reddy
  • 900
  • 2
  • 7
  • 13
2
votes
1 answer

QAbstractTableModel retrieve custom object on data changed

I have recently picked up Qt again, and started refreshing my memory. Creating a custom data model for a table was easy enough. Now I am trying to retrieve the selected data. Take note that I use custom data objects. Example of my custom…
Joey Roosing
  • 2,145
  • 5
  • 25
  • 42
2
votes
2 answers

QAbstractTableModel data return html code to display

I want my AbstracttableModel subclass data() method to return html i.e. PreTextTextPostText And this text must be displayed int table as in html: PreTextTextPostText How can I do this?
zabulus
  • 2,373
  • 3
  • 15
  • 27
1
vote
2 answers

How to add an item to a model in Qt4 and get an index for the newly aded item

I have a window which contains a QTreeView (databaseTreeView) on a subclass of QAbstractTableModel (via a QSortFilterProxyModel). I have an [Add] button which calls…
M_M
  • 1,955
  • 2
  • 17
  • 23
1
vote
3 answers

Is there a generic TableModel we can use in JTables?

I'm now looking into JTables and have a bunch of business objects that I retrieve from the DB with Hibernate + Spring Data JPA. I love that Spring Data JPA handles all the cumbersome implementation of the DAL and was wondering if there's something…
Joao Coelho
  • 2,838
  • 4
  • 30
  • 36
1
vote
1 answer

Qt: How to synchronize access to data from multiple threads in model/view setup?

How to synchronize access to data accessed from multiple threads in Qt model/view setup? I'm using QTableView with a Model class. Model extends QAbstractTableModel and has an instance of a custom class Net that holds actual data to be displayed to…
stefanB
  • 77,323
  • 27
  • 116
  • 141
1
vote
2 answers

How to update QSqlTableModel after database connection has been changed changed

I have class which is derived from QSqlRelationalTableModel. I use SQLite database. And I need to change database file. I close old database file, call SetDatabaseName("path to new file") and open new database file. Now I just call select() for the…
Funt
  • 399
  • 8
  • 23
1
vote
1 answer

Changing QAbstractTableModel headerData using the role

I have a subclass class TableModel : public QAbstractTableModel I override the headerData method as follow: QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole && orientation ==…
andre
  • 7,018
  • 4
  • 43
  • 75
1
vote
1 answer

Hide column in QAbstractTableModel

I have a self created Qt-Model derieved by QAbstractTableModel. The data behind the model contains multiple QUuid-columns, whose cell-data I need to pass around the application. Due to design-reasons I don't want to show the QUuid-columns to the…
Me3nTaL
  • 139
  • 2
  • 11