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
3
votes
2 answers

Qt: distinguish between drag from same or other window

I am using a QTableView, on which I set my own custom model, inheriting from QAbstractTableModel, using a call to QTableView::setModel(). The table view supports drag and drop: my model class reimplements mimeData() and dropMimeData(). Items can be…
user377486
  • 693
  • 2
  • 10
  • 19
2
votes
1 answer

QTableView doesn't seem to react on dataChanged signal

Shown below is the my custom table model. I am trying to use that tablemodel together with a QTableView. If the method append of the table model is called I would expect the table view to update its contents. But it doesn't and I don't know why. If…
Christian
  • 2,214
  • 4
  • 26
  • 37
2
votes
1 answer

PyQt5: Implement removeRows for pandas table model

I use QTableView to display and edit a Pandas DataFrame. I use this method in the TableModel class to remove rows: def removeRows(self, position, rows, QModelIndex): start, end = position, rows self.beginRemoveRows(QModelIndex,…
2
votes
2 answers

Using QItemDelegate with QAbstractTableModel

I have a QAbstractItemModel and a QItemDelegate and here is my problem. The Delegate does nothing. Its subroutines are being called but nothing happens. Here is what I would like to see in my table. Text : QComboBox : Text : Text :…
jecjackal
  • 1,407
  • 2
  • 20
  • 35
2
votes
1 answer

Insert and remove row in pyqts QTableView using the QAbstractTableModel

How can i insert and delete single rows in a QTableView using the QAbstractTableModel. A new row will be given in a seperate thread which is connected via a pyqtsignal to the QAbstractTableModel. The goal is to add a row every time a new emit is…
progS
  • 55
  • 5
2
votes
1 answer

PushButton in Qt Model/View Table

I'm writing a custom TableModel in PyQt5, inheriting from QtCore.QAbstractTableModel. I want my Table to have one column with CheckBoxes only, no text, and one column with a PushButton in each row. I tried to return a QPushButton object in the data…
julian
  • 35
  • 7
2
votes
1 answer

Subclassing QAbstractTableModel

I have subclassed a QAbstractTableModel to represent data from a QMap. This QMap has QLists of QSqlRecords and this map is modified by some other part of my code. I want to use this model with a QTableView to display the sql records in this map for…
kasper360
  • 367
  • 2
  • 4
  • 14
2
votes
1 answer

Show certain columns in QTableView

Suppose I have QAbstractTableModel which feeds 2 QTableView. One tableview shows all data in the model. Please advise how can I approach to specify the other tableview to show only 2 columns from the same model.
Ahmed Sonbaty
  • 97
  • 1
  • 9
2
votes
1 answer

Qt: What to emit when inserting items into my model to hint to the view to recheck canFetchMore?

I have a custom model (extends QAbstractTableModel) where row data is added pragmatically. For performance reasons, I am using the fetch functionality (canFetchMore, fetchMore) to avoid UI lag when items are not visible. When a new row is inserted,…
2
votes
1 answer

Sorting case insensitively in QAbstractItemModel

I have trouble with trying create my own sorting function with QAbstractItemModel. It works but not case insensitive. I have tried to use QSortFilterProxyModel, but any success. My sort function: def sort(self, col, order): …
Dave
  • 87
  • 9
2
votes
0 answers

QTableView: Cell contents are cleared during editing

Following is the problem : When I am editing a cell in QTableView,in middle of editing the udpates on the underlying model clears the cell and write the new Data. I want that during the editing of the cell the new data change should not overwrite…
mapuna
  • 53
  • 1
  • 5
2
votes
1 answer

qtableview add rows from a query and edit them in python

i use Python 2.7, MariaDB and Qt4. I have a table in which i want to insert rows from a query. I tried self.model = QtSql.QSqlQueryModel() but i found that this is only read only. Then i moved to something else. My Model() class looks like…
admin.unu
  • 165
  • 1
  • 15
2
votes
2 answers

PySide QTableView setData for multiple cells

I'm using a QTableView and sub-classed a QAbstractTableModel. When editing a cell I noticed that QAbstractTableModel.setData only goes through the last selected cell. Is there a way to get setData to work with multiple (selected) cells? As an…
Green Cell
  • 4,677
  • 2
  • 18
  • 49
2
votes
1 answer

How to control sorting arrow indicator on QTableView

When this QTableView is created I want the sorting "arrow" indicator to be shown on the column at the middle. The arrow needs to be pointing down. How to achieve this? from PyQt4 import QtCore, QtGui app = QtGui.QApplication([]) class…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
2
votes
3 answers

How to sort QTableView in Qt4 and up

Code creates a single QTableView. The column sorting was enabled. When I click the column name (1,2 or 3 nothing happens). How to make this sorting work without using proxy model? from PyQt4 import QtCore, QtGui app =…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
1 2
3
13 14