Unsolved QSqlTableModel ; how can I show my PNG data?
-
How I can show the PNG data in the cell for QSqlTableModel ?
-
@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? -
@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.
-
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.
-
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.
-