Hi wysota, thanks for reply.
I just had no idea how to implement it.
Now I have done it the following way:
I've created a new model class based on QSqlQueryModel and implemented data() method:
{
if (role == Qt::DecorationRole)
{
switch(item.column())
{
case 0: // column 0 contains text data
image.loadFromData(record(item.row()).value(1).toByteArray()); // column 1 contains BLOB data
return image.scaled(160, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
}
}
QVariant SqlQueryModel::data ( const QModelIndex & item, int role) const
{
if (role == Qt::DecorationRole)
{
switch(item.column())
{
case 0: // column 0 contains text data
QPixmap image;
image.loadFromData(record(item.row()).value(1).toByteArray()); // column 1 contains BLOB data
return image.scaled(160, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
}
return QSqlQueryModel::data(item, role);
}
To copy to clipboard, switch view to plain text mode
Then I connected it to QListView like this:
m_pQueryModel = new SqlQueryModel(this);
m_pQueryModel->setQuery(m_sQuery, m_sqlDatabase);
pView->setModelColumn(0);
pView->setModel(m_pQueryModel);
m_pQueryModel = new SqlQueryModel(this);
m_pQueryModel->setQuery(m_sQuery, m_sqlDatabase);
QListView *pView = new QListView(ui.tab_2);
pView->setViewMode(QListView::IconMode);
pView->setModelColumn(0);
pView->setModel(m_pQueryModel);
To copy to clipboard, switch view to plain text mode
I'm curious whether it's correct solution or it can be improved somehow.
Thanks,
Alex
Bookmarks