qsqltablemodel

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

Set color to a QTableView row

倖福魔咒の 提交于 2019-11-29 02:14:58
void MyWindow::initializeModelBySQL(QSqlQueryModel *model,QTableView *table,QString sql){ model = new QSqlQueryModel(this); model->setQuery(sql); } With this method i can set a QSQlQueryModels to my QTableviews. But How i can set color to a row based on a cell value? The view draws the background based on the Qt::BackgroundRole role of the cell which is the QBrush value returned by QAbstractItemModel::data(index, role) for that role. You can subclass the QSqlQueryModel to redefine data() to return your calculated color, or if you have Qt > 4.8, you can use a QIdentityProxyModel : class MyModel

How to refresh a QSqlTableModel while preserving the selection?

余生长醉 提交于 2019-11-28 08:31:31
I am using a QSqlTableModel and QTableView to view an SQLite database table. I would like to have the table auto refresh every second or so (it's not going to be a very large table - a couple of hundred rows). And i can do this - like so: QTimer *updateInterval = new QTimer(this); updateInterval->setInterval(1000); updateInterval->start(); connect(updateInterval, SIGNAL(timeout()),this, SLOT(update_table())); ... void MainWindow::update_table() { model->select(); //QSqlTableModel* sqlTable->reset(); //QTableView* } But this removes any selection I have, so the selections only last for up to a

How to refresh a QSqlTableModel while preserving the selection?

我是研究僧i 提交于 2019-11-27 02:23:34
问题 I am using a QSqlTableModel and QTableView to view an SQLite database table. I would like to have the table auto refresh every second or so (it's not going to be a very large table - a couple of hundred rows). And i can do this - like so: QTimer *updateInterval = new QTimer(this); updateInterval->setInterval(1000); updateInterval->start(); connect(updateInterval, SIGNAL(timeout()),this, SLOT(update_table())); ... void MainWindow::update_table() { model->select(); //QSqlTableModel* sqlTable-