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

emit dataChanged(createIndex(1,1),createIndex(1,1)) results in many ::data invocations

I have a QTableView and a corresponding instance of a child of QAbtractTableModel. I was surprised to see that if my table model instance emits a dataChanged naming a single cell, the Qt framework will then issue a large number of calls to my table…
Eric Johnson
  • 696
  • 4
  • 23
4
votes
1 answer

When is param "QModelIndex &parent" in QAbstractTableModel::columnCount and/or QAbstractTableModel::rowCount useful?

Trying to understand QAbstractTableModel more, I came across the virtual methods of rowCount and columnCount which need to be implemented when subclassing QAbstractTableModel. Take int QAbstractItemModel::columnCount(const QModelIndex &parent =…
JackOuttaBox
  • 345
  • 5
  • 12
4
votes
1 answer

QTableView- overriding CSS in QAbstractTableModel

I am using commmon css for our product which has templates for QTableView as below QTableView::item { padding-left:10px; height:40px; width:80px; color: #5a5a5a; border-bottom :1px solid #f0f0f0; } In one case, I want to change…
4
votes
2 answers

Qt5 QTreeView with custom model and large data very slow scrolling

I have custom data that I need to display in a QTreeView. I have derived my model from QAbstractTableModel, and made my own implementations of rowCount(), columnCount(), data(), and headerData(). The model has a local QList> to support it, and the…
bmahf
  • 965
  • 2
  • 11
  • 27
4
votes
3 answers

How to insert QPushButton into TableView?

I am implementing QAbstractTableModel and I would like to insert a QPushButton in the last column of each row. When users click on this button, a new window is shown with more information about this row. Do you have any idea how to insert the…
izidor
  • 4,068
  • 5
  • 33
  • 43
4
votes
1 answer

Can I use interaction with QAbstractTableModel's data in QThread?

I know that we can't use GUI-interaction in non-GUI threads (QThread). But I don't know if we can or can't interact with model (QAbstractItemModel) in threads and if True then how to do it in the right way? I honestly searched something about this…
Крайст
  • 776
  • 1
  • 9
  • 22
3
votes
2 answers

QTableView change row color based on a value

I have a QTableView that I implemented with my own model subclassed from QAbstractTableModel. I want to be able to change the row color to red when one of the fields in the row has a certain value. I saw a lot of examples where the answer is to…
MBU
  • 4,998
  • 12
  • 59
  • 98
3
votes
1 answer

How to color cells after creat a Qtableview using a custom QAbstractTableModel

I create a class 'pandasModel' based on QAbstractTableModel, shown below: import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * class pandasModel(QAbstractItemModel): def __init__(self, data,…
xufang
  • 71
  • 1
  • 4
3
votes
1 answer

QTableView model crash when calling endInsertRows()

I have been trying to update a QTableViewModel when inserting a new object that represents a row. I did follow the advise of several question in SO, but I cannot get an example to work. After debugging, I found that the call to self.endInsertRows()…
Santi Peñate-Vera
  • 1,053
  • 4
  • 33
  • 68
3
votes
1 answer

tableview not updated after sort on tablemodel

The idea is to display a dataframe via the PyQt5 MV programming idiom and perform some basic sorting and filtering operations on the presented dataframe. The displaying part all went fine however now I am stuck on the sorting part of the tool. Print…
3
votes
0 answers

Qt(PySide) Filtering Rows using ProxyModel

Hey I am trying build a table with a multiple filtering functions on top of each other. I have already figured out how to filter rows with search strings using RexExp and QSortFilterProxy on top of QAbstractTableModel. But I also would like the…
bop
  • 435
  • 1
  • 3
  • 11
3
votes
2 answers

Edit table in PyQt QAbstractTableModel without deletion of content

What I have done so far: I'm implementing an custom QAbstractTableModel (used in a QTableView-Widget) that contains editable cells. The properties of these cells are specified in my flags() method that looks like this: def flags(self, index): # Qt…
user6205205
3
votes
2 answers

How to change underlying data of QAbstractTableModel completely?

This is my first post here, but i received a lot of help from all of you guys, since i started programming. I am new to Qt and try to make my first project at the moment. My question is about the communication between the model, the underlying data…
syc
  • 73
  • 1
  • 8
3
votes
1 answer

Why using QAbstractTableModel instead of QAbstractListModel?

I've implemented TableView in QML using TableViewColumns with some roles like this: TableView { TableViewColumn { role: "role1" title: "Role1" } ... } It's bound to a C++ model, inherited from QAbstractListModel with all…
3
votes
2 answers

How to hide checkboxes in a QTableView using python?

I'm quite new to python as well as to Qt. I would like to use the QTableView without checkboxes appearing in the tableview's cells, but as it seems they just appear there by default. As I've found out so far, you just have to deactivate the…
MKa
  • 71
  • 7
1
2
3
13 14