QSqlTableModel ; how can I show my PNG data?
-
wrote on 6 Nov 2018, 15:41 last edited by
How I can show the PNG data in the cell for QSqlTableModel ?
-
How I can show the PNG data in the cell for QSqlTableModel ?
wrote on 6 Nov 2018, 16:06 last edited by@RahibeMeryem
When you say "PNG data", do you mean you want to show the data as raw data bytes (0x...
or whatever), or do you mean you want to show the actual picture? -
wrote on 6 Nov 2018, 16:40 last edited by RahibeMeryem 11 Jun 2018, 16:40
@JonB PNG image.. sorry . actual picture ...
-
You can make it as QByteArray when you fetch from table. While showing you can construct the byte array as PixMap or QImage.
-
wrote on 6 Nov 2018, 16:45 last edited by
I can construct QPixmap from PNG / ByteArray,
What I dont know is how to show in QSqlTableModel.
I can show in normal table thats ok.
I want to make a db-table browser for user to see data.
Best
-
QSqlTableModel should be used with view to display. Use QTableView to display model contents. If you are using the TableView, custom delegate may be required display this image.
If you are using the QTableWidget, you can QListWidgetItem and setIcon role.
-
wrote on 7 Nov 2018, 07:25 last edited by RahibeMeryem 11 Jul 2018, 07:32
any example for siple delegate . ?
QSqlTableModel *model = new QSqlTableModel( nullptr, db_history); model->setTable("persondb"); model->setEditStrategy(QSqlTableModel::OnManualSubmit); model->select(); model->setHeaderData(0, Qt::Horizontal, tr("id")); model->setHeaderData(1, Qt::Horizontal, tr("name")); model->setHeaderData(2, Qt::Horizontal, tr("date")); model->setHeaderData(3, Qt::Horizontal, tr("PHOTO")); model->setHeaderData(4, Qt::Horizontal, tr("location")); model->setHeaderData(5, Qt::Horizontal, tr("category")); ui->history_table->setModel(model); ui->history_table->hideColumn(0); // don't show the ID ui->history_table->show();
This my table.
-
wrote on 7 Nov 2018, 08:48 last edited by
6/8