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
1
vote
1 answer

using data shared between multiple threads in a QAbstractTableModel

I have a singleton class implemented using Q_GLOBAL_STATIC that contains a data structure that has to be accessed from multiple threads, I implemented accessor functions in the class, that would lock a mutex before accessing the data, so that all…
Mike
  • 8,055
  • 1
  • 30
  • 44
1
vote
2 answers

How to get checkbox in first column of QTableView in pyqt

In my QTableView, I am trying to have first column of checkboxes but i am getting all the row columns filled with checkboxes and also all of them are checked by default. I am not able to changed the state of checkboxes either. class…
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
1
vote
0 answers

How to implement read and write on a file from QAbstractTableModel to

I am using Qt Xlsx to edit and write my xlsx file. I want to make a program that can read and write on *.xlsx file via QAbstractTableModel. But i got confuse how to implement read and write that file via QAbstractTableModel. How can i do this ?
lappet
  • 116
  • 1
  • 7
1
vote
1 answer

How to inform the model/view that underlying data changed table headers?

I just constructed a read-write TableModel based on QAbstractTableModel. Works, but the underlying data can change the headers of columns and rows, and I have no idea how to inform the model and views about that (so that views refresh the…
MaciekS
  • 401
  • 8
  • 18
1
vote
0 answers

Get CSV from QSQLTableModel with correct Locale

I'm trying to convert the QTableView filled with QSQLTableModel data into CSV file. My current code is the following (actually similar to what was posted here already): QFile f( "table.csv" ); if (f.open(QFile::WriteOnly | QFile::Truncate)) { …
1
vote
1 answer

How to select QTableView index or row from inside of Model

The posted code creates a singe Model/Proxy QTableView. The multi-selection feature has been enabled for it. There are four items total. Two of them include a character "A". Other two include character "B" in their "item" names. QPushButton when…
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
1
vote
2 answers

Custom editor in QAbstractTableModel

Does anyone have an example of using a QWidget as an editor in a QAbstractTableModel? I have a column which when edited should create a QCombobox with the list of choices. The docs seem to suggest I need to write a QAbstractItemDelegate and a custom…
Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
1
vote
2 answers

Return row number in QAbstractTableModel headerData

I am using QTableView and QAbstractTableModel. Can I get ordered row numbers in vertical header even after filtering and sorting?
fpohtmeh
  • 506
  • 4
  • 15
1
vote
2 answers

Using a QCompleter in a QTableView with Qt and Python

I'm reading up on how to make my QAbstractTableModel editable, and it looks pretty straightforward. But how do I set up an editable cell to use a QCompleter? I take it somehow I have to tell the QTableView to use a QLineEdit widget? How can I do…
Jason S
  • 184,598
  • 164
  • 608
  • 970
1
vote
1 answer

QtQuick TableView CheckBox delegate calling setData function of QAbstractTableModel

I have trouble connecting TableView in qml and setData function of QAbstractTableModel in QT . My idea is to be able to check activities as "done" via CkeckBox delegate. I tried overwriting the setData function to work with row instead QmodelIndex…
1
vote
1 answer

QTableView::edit( const QModelIndex &index ) failed

I am trying to prevent user from entering the same data into my model, which is subclassed from QAbstractTableModel. bool MyModel::setData( const QModelIndex &index, const QVariant &value, int role ) { bool result = false; ... // Test if…
pau
  • 352
  • 3
  • 14
1
vote
1 answer

QDataWidgetMapper and QAbstractTableModel

I have a QAbstractTableModel displayed by a QTableView. The table has 2 columns and a couple of rows. Each cell is a QLineEdit. My question is if there is a way of using QDataWidgetMapper::addMapping with my custom model (for the QLineEdit cells).
user20679
  • 442
  • 4
  • 17
1
vote
3 answers

How to correctly access QMap in QAbstractTableModel::data()

I got a QMap with an identifier and a corresponding object. When subclassing QAbstractTableModel::data() you get a QModelIndex with row and column, respectively. Each row should represent one object (QAbstractTableModel::rowCount() is…
braggPeaks
  • 1,158
  • 10
  • 23
1
vote
3 answers

how can i achieve to update multiple rows in a qtableview

I have a customized qtablemodel and a qtableview. I would like to add a feature that the user can select multiple rows and by changing one of the values within this rows. He would actually change this value in all rows. e.g. the user could change…
Donny
  • 549
  • 2
  • 10
  • 24
1
vote
2 answers

Qt QAbstractModel looking for data

I have my own QAbstractTableModel connected to SQLite. I get data from database and write it to my list by column name. I don't want handle to my table by SQL query when I'm looking for data. What do you think about? Is it normal? Please give me…
developer
  • 37
  • 1
  • 6