Questions tagged [qsqltablemodel]

A QSqlTableModel instance is used in the Qt framework to provide an editable data model for a single database table.

QSqlTableModel is a high-level interface for reading and writing database records from a single table. It is built on top of the lower-level QSqlQuery and can be used to provide data to view classes such as QTableView.

QSqlTableModel can also be used to access a database programmatically, without binding it to a view.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

206 questions
3
votes
2 answers

how to set/read QSqlRelationalTableModel column properties and constraints?

Is there any way to check properties and constraints for each column in a QSqlRelationalTableModel? For example, I'd like to ask my QSqlRelationalTableModel object whether a certain column can contain nulls, or what datatype is valid for that…
David Burson
  • 2,947
  • 7
  • 32
  • 55
2
votes
1 answer

Inconsistent behavior of QSqlTableModel with OnRowSubmit

Premise: this question possibly refers to two distinct problems, but I believe they might be linked. If, after comments and further research we will find out that they are actually unrelated, I will open a separate question. I'm experiencing some…
musicamante
  • 41,230
  • 6
  • 33
  • 58
2
votes
1 answer

qtableview fails to display the newly inserted row

When using QtableView + QSqlTableModel combination, QtableView fails to properly display the inserted row after insertion of a new one. The id field is hidden. The EditStrategy is OnFieldChange. There is a button to insert a new empty row at the end…
2
votes
1 answer

how to insert all column header names into a list from qsqltablemodel table?

Below is my db model example: db = QSqlDatabase.addDatabase('QSQLITE') db.setDatabaseName('book.db') db.open() self.model = QtSql.QSqlTableModel(self) self.model.setTable("card") self.model.select() column_names = [ ] How to get all column header…
user3030327
  • 411
  • 1
  • 7
  • 19
2
votes
1 answer

How to insert row from list into QSqlTableModel?

Below is my example code. class UI(QMainWindow): def __init__(self): super(UI, self).__init__() uic.loadUi("tableview.ui", self) self.show() db = QSqlDatabase.addDatabase('QSQLITE') …
user3030327
  • 411
  • 1
  • 7
  • 19
2
votes
1 answer

How to create filter rows for Qtableview with using QSqlTableModel.?

Is it possible to create row filter for Qtableview with QSqlTableModel. I am sing " QSqlTableModel" to show the data on Qtableview from SQLite thats working. But i am trying to filter rows. When i am executing the code i am getting below error…
user3030327
  • 411
  • 1
  • 7
  • 19
2
votes
1 answer

QSqlTableModel setFilter too many arguments

I'm trying to assign a signal to a pushbutton so that it calls a function which filters and shows specific data on tableView. but when i click on the button it says: Type error: setFilter(self, str) too many arguments and the application…
Sherafati
  • 196
  • 1
  • 10
2
votes
1 answer

Error on Submit after Inserting a Row in QSqlTableModel - No Fields to update

I have a SQLite database table with the following schema: TABLE IenState ( Id primary key, NetId integer, NodeId integer, DevType text Qos integer ) Using a DB Browser utility I inserted a record in the table. I…
Jatala
  • 93
  • 1
  • 11
2
votes
1 answer

QSqlTableModel::setData() returns false also with Qt::EditMode

The documentation of QSqlTableModel::setData() says: Returns false if the role is not Qt::EditRole. To set data for roles other than EditRole, either use a custom proxy model or subclass QSqlTableModel. but I still get false even if the the role…
Mark
  • 4,338
  • 7
  • 58
  • 120
2
votes
1 answer

QML Combobox with QSqlModel

I'm currently facing problems with populating a QML Combobox with a QSqlTableModel. Example Database: Table Customer Table Project | id | name | | id | name | fk_customer | |........|..........| …
Stephan
  • 143
  • 1
  • 8
2
votes
1 answer

Slot called twice qt

I have an editable list view inside a dock widget. I wanted to keep the track of the data before the user edits and the data after the user edits. The complete concerning code is: void MainWindow :: createDock() { //initialize dockWidget …
Hemil
  • 916
  • 9
  • 27
2
votes
1 answer

CheckBox in QListView using QSqlTableModel

I am learning the PyQt5 framework and attempting to build a QListView of items with a checkbox in front of each item. Most of the examples I have read don't show how to accomplish this with the QSqlTableModel. Can someone please point me in the…
Elcid_91
  • 1,571
  • 4
  • 24
  • 50
2
votes
1 answer

Get values in one or more joined tables using PySide

I'm trying to understand the advantage of using QSqlRelationalTableModel versus QSqlTableModel when dealing with tables linked through unique IDs. In the following example, the organization field is correctly displayed by name instead of by ID…
davideps
  • 541
  • 3
  • 13
2
votes
1 answer

QTableView formatting numbers

I have created a delegate and i'm able to align and boldface the numbers on the table. I would like to force them to have two decimal places, for example 1.2 should show as 1.20. This is the header of the delagete: #ifndef TOTALDELEGATE_H #define…
Dan3460
  • 95
  • 3
  • 13
2
votes
1 answer

How to format a column with decimal numbers in QSqlTableModel

I have got a QSqlTableModel with decimal numbers in one column. How can I format this column to have numbers with 4 decimal places (e.g.: 2,3 --> 2,3000; 4,567891 --> 4,5679). I am using pyqt5. Edit: I tried to subclass QSqlTableModel like…
vezzon
  • 177
  • 1
  • 11
1
2
3
13 14