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

How to set row height of QTableView?

I have QTableView and QAbstractTableModel. I require rows to have height equal to 24. I know the only way to do this is by calling QTableView::setRowHeight. Since the model is dynamic it may be added new rows, but I don't want to call setRowHeight…
Ashot
  • 10,807
  • 14
  • 66
  • 117
19
votes
2 answers

How to set data inside a QAbstractTableModel

I need to implement a table with Qt. I believe I'll be suing a QAbstractTableModel, with a QTableView using this model. I understand I'll have to edit the rowCount(), columnCount(), and data() functions of the model. However, I don't understand how…
user1173240
  • 1,455
  • 2
  • 23
  • 50
17
votes
2 answers

Qt QTableView how to have a checkbox only column

We are using a QTableView with Qt 4.6.3, and need a column that only has a checkbox in each cell. We're using a custom subclass of QAbstractTableModel as the model for the QTableView. Right now, we have a checkbox by setting the…
David Burson
  • 2,947
  • 7
  • 32
  • 55
17
votes
2 answers

How to change the header background color of a QTableView

The following is what I've currently tried. The header text changes color correctly but the background will not change from the default. template inline QVariant TableModel::headerData(int section, Qt::Orientation orientation, int…
andre
  • 7,018
  • 4
  • 43
  • 75
15
votes
3 answers

PyQt: Adding rows to QTableView using QAbstractTableModel

I am super new to Qt programming. I am trying to make a simple table that can have rows added by clicking a button. I can implement the table fine but can't seem to get the updated data to show on the table. I believe my problem stems from the fact…
user3439556
  • 153
  • 1
  • 1
  • 5
12
votes
5 answers

What is the best way to display an animated icon in a QTableView?

I've been struggling with this for some times now, and I can't seem to find the right way to do this. What I would like is the ability to use an animated icon as a decoration for some of my items (typically to show that some processing is occuring…
Luc Touraille
  • 79,925
  • 15
  • 92
  • 137
11
votes
3 answers

Qt Delete selected row in QTableView

I want to delete a selected row from the table when I click on the delete button. But I can't find anything regarding deleting rows in the Qt documentation. Any ideas?
laura
  • 2,085
  • 13
  • 36
  • 68
9
votes
2 answers

Edit table in pyqt using QAbstractTableModel

I'm trying to create an editable table in PyQt. Here's the code for just displaying the table: import sys from PyQt4 import QtGui, QtCore from PyQt4.QtCore import * from PyQt4.QtGui import * # données à représenter my_array = [['00','01','02'], …
nam
  • 3,542
  • 9
  • 46
  • 68
7
votes
1 answer

Set initial text when editing a QTableView cell

I've subclassed QAbstractTableModel and overrode the flags() method so that some of the table cells are editable. The problem is that when I start editing, the existing cell value is erased. I would like to initially have the existing cell value…
bdforbes
  • 1,486
  • 1
  • 13
  • 31
6
votes
1 answer

How do I call dataChanged

The following is my add a row class. It is called by the code, not the table and I want it to properly call dataChanged when a new row is added, although this isn't working, the table doesn't do anything. What am I doing wrong? void…
Will03uk
  • 3,346
  • 8
  • 34
  • 40
6
votes
1 answer

QAbstractTableModel editing without clearing previous data in cell

I have created a model based off of QAbstractTableModel that allows the user to edit data in that model. The model is displayed in a QTableView in a QMainWindow. So far in my model I am able to make the cells editable, and save whatever the user…
DaveK
  • 658
  • 8
  • 21
6
votes
2 answers

QTableView + QAbstractTableModel: Move rows via drag'n'drop

I have a simple QAbstractTableModel-based model and a QTableView for it. My aim is simple as well: allow to move/reorder rows via drag'n'drop. Notes: D'n'd changes inside QTableView should be reflected in my model; D'n'd supposed to be internal -…
Nikolai Shalakin
  • 1,349
  • 2
  • 13
  • 25
5
votes
3 answers

QAbstractTableModel and emit dataChanged for a single row

I derived a model from QAbstractTableModel and now I want to notify, that the data of a whole row has been changed. If for example the data of a row with index 5 is changed (4 columns), than using the following code works as expected. emit…
SoulfreezerXP
  • 459
  • 1
  • 5
  • 19
5
votes
0 answers

How to get current column and its sorting direction of QTableView

This code creates a single QTableView. Clicking the column displays the arrow that indicates the direction of column sorting. Clicking the tableView's item itself prints out the clicked index. When the tableView item is clicked I want to know what…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
5
votes
1 answer

Center align the contents of cells in QTableView

I've a QTableView. Is there a way to align to the centre, all the cell contents of this view? I'm not using any delegate. It's just an AbstractTableModel which is added as a model to a QTableView. How should I align each cell content to the…
user1173240
  • 1,455
  • 2
  • 23
  • 50
1
2 3
13 14