qsqltablemodel

QSqlRelationalTableModel with QSqlRelationalDelegate not working behind QAbstractProxyModel

十年热恋 提交于 2019-12-12 01:55:38
问题 I need to swap the rows and columns of a QSqlRelationalTableModel. After a lot of searching, I wrote a little proxymodel to flip the rows and the columns. It is partly working. The relations in the table are resolved and showed but the dropboxes to choose them gets lost. Also, how do I get them to update? Here is a little self-contained script that reproduces the behavior. Where is my error? I have strong suspicion that it has to do with the signals and slots of the models but I haven't found

QSQLTableModel inheritor and QTableView

走远了吗. 提交于 2019-12-11 08:14:22
问题 I wrote QSQLTableModel inheritor for working with qml and it's work well. I need use it with QTableView too, data shows, but I cannot modify it - when I edit everything is ok, but all changes drop when I get out from field (I know about editStrategy, but the problem occurs earlier). I suppose that something wrong with virtual function, but I cant undestant what. If i create QSqlTableModel with the same parameters, everything is ok. Somebody have any idea how can i fix this? My code: h: class

Implementing setEditStrategy in editable QSqlQueryModel

社会主义新天地 提交于 2019-12-05 05:16:14
This is a follow-up to this question . In there, we created an editable subclass of QSqlQueryModel, to use with complex queries. Now I need to add a functionality like QTableModel's setEditStrategy so I can cache all changes and accept or revert them using buttons. PyQt apparently doesn't allow multiple inheritance and I cannot find sufficient documentation to re-implement this method in my custom model, therefor here's the question: How can I re-implement QSqlTableModel.setEditStragety (or something like it) including RevertAll() and SubmitAll() in an editable QSqlQueryModel? Here's a CVME:

When or how to use fetchMore() on QSqlTableModel with a SQLite database for rowCount() to work?

别来无恙 提交于 2019-12-04 09:59:37
My class DataTable is derived from QAbstractTableModel. It uses a QSqlTableModel object internally to fetch data from a db table. It represents a record for every row in the db (it does more but the record count is always the number of rows in the db table). With MySql, my DataTable::rowCount() implementation just calls rowCount() on the QSqlTableModel, which works nicely. Now with SQLite, Qt's SQLite driver returns a row count of 256 if there are more than 256 rows in the db table, so my DataTable class also returns 256 - which is wrong. The documentation tells me to call while (sql_model-

Editable QTableView of complex SQL query

江枫思渺然 提交于 2019-12-02 12:31:16
How can I make an editable QTableView displaying data from a complex SQLite query? I need to fill a QTableView with data from several SQLite tables. This needs to be editable by the user. As the queries are a bit complex (including JOINs and CASE WHEN etc.), I'm doing this via a QSqlTableModel and a QSqlQuery. I have been told, however, that this is not how QSqlTableModels should be used. So, can someone please show me how to get a result like the one shown here via the proper way? Also, while my QTableViews are editable, the results don't seem to get stored in the SQLite database. (When I

QTableView formatting numbers

陌路散爱 提交于 2019-12-02 03:19:05
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 TOTALDELEGATE_H #include <QObject> #include <QStyledItemDelegate> class TotalDelegate : public QStyledItemDelegate { public: TotalDelegate(); virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE; }; #endif // TOTALDELEGATE_H Here is the implementation: #include "totaldelegate.h"

QTableView formatting numbers

做~自己de王妃 提交于 2019-12-02 02:32:00
问题 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 TOTALDELEGATE_H #include <QObject> #include <QStyledItemDelegate> class TotalDelegate : public QStyledItemDelegate { public: TotalDelegate(); virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q

How to change orientation of Qt TableView

痞子三分冷 提交于 2019-12-01 20:44:12
问题 Hi I am using a QTableView to display data from a sql table using the qsqltablemodel asfollows: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); model = new QSqlTableModel(this); model->setTable("staging"); model->select(); model->setHeaderData(0, Qt::Vertical, tr("ID")); model->setHeaderData(1, Qt::Vertical, tr("Region")); model->setHeaderData(2, Qt::Vertical, tr("T1")); model->setHeaderData(3, Qt::Vertical, tr("N1")); model-

How to change orientation of Qt TableView

北慕城南 提交于 2019-12-01 18:30:01
Hi I am using a QTableView to display data from a sql table using the qsqltablemodel asfollows: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); model = new QSqlTableModel(this); model->setTable("staging"); model->select(); model->setHeaderData(0, Qt::Vertical, tr("ID")); model->setHeaderData(1, Qt::Vertical, tr("Region")); model->setHeaderData(2, Qt::Vertical, tr("T1")); model->setHeaderData(3, Qt::Vertical, tr("N1")); model->setHeaderData(4, Qt::Vertical, tr("M1")); ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); ui

How to display content of multiple QSqlTableModels in one QTableView?

半城伤御伤魂 提交于 2019-12-01 01:15:50
I have a MySql table, let's call it x : CREATE TABLE x ( Id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, A int unsigned NOT NULL, B int, FOREIGN KEY (A) REFERENCES y(Id) ); And then I have another table, let's call it y : CREATE TABLE y ( Id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, First varchar(255), Last varchar(255) ); I want to display table x in one QTableView and in place of column A from table x I want to display columns First and Last from table y from row whose Id is equal to A from table x . Do you have any ideas? Let me know if my explanation is not clear enough. You

工具导航Map