Not really a lot. Something like this (compiles but untested):
Qt Code:To copy to clipboard, switch view to plain text mode
Not really a lot. Something like this (compiles but untested):
Qt Code:To copy to clipboard, switch view to plain text mode
hsm13 (9th November 2011)
wow that's great; Thank you so much.
Is PDF file is different than image ? and can I display it in hyperlink label to open it with outside application ? Many thanks again.
ummm, sample code if found please
Let's take a deep breath; In fact I found you post here
http://www.qtcentre.org/threads/4499...light=pdf+blob
It's a bit different; so where I want some tricky help. sorry for any disturb.
Good Morning to all,
I've the same problem, but in a QSqlRelationalModel, so, how I should use this delegate?
I've got a table with severals column so, now I use a QSqlRelationalDelegate (I've also 3 QCombobox at 3 relations), so how can I switch from one delegate to other? Or I can subclass QSqlRelationalDelegate to obtain this? And your code affect only the QLabel behavior? The other columns will work as before?
Thanks for your time!
Michele
The delegate code I posted is an example. It assumes that if the editor is a QLabel that the corresponding column in the model is a blob containing an image. It also shows how the current image in the label can be written back to the model. If the editor widget, this was for mapped widgets not a table view, was not a label then no data would be transferred in either direction.
Delegates are attached to a view, not model or table, either as a whole or to a column/ row of the the view (see QAbstractItemView::setItemDelegate(), setItemDelegateForColumn, setItemDelegateForRow). If you use one delegate for the whole view then your delegate usually needs to differentiate between columns using index.column() and do something different for each in the setEditorData() and setModelData() functions. If you use a delegate on a single column then the example is the sort of thing you need.
The default relational delegate should look after creating an populating combo box editors for established relationships and do the default for other columns. You can put separate delegates on columns if you wish or write a combined delegate by subclassing the relational delegate.
What are you trying to achieve?
I'm trying to achive the same effect needed by hsm 13but I'm using a QSqlRelationalTableModel and QDataWidgetMapper, and I don't know how to use your example.
If I assign your delegate to the mapper [mapper->setItemDelegate(new PicLoadingDelegate(this));], I lose the link of other fields of my form.
I use QLabel to show the image stored into Blob file.
Thanks a lot
Michele
You can only attach the delegate to the mapper as a whole so it will affect all the columns and you need to write the delegate to discriminate between columns accordingly. The related columns should be handed off to the superclass to get default combo box treatment. Something like:
Qt Code:
Q_OBJECT public: { switch(index.column()) { case 0: // do nothing special, simple editors case 1: break; case 2: // do something special for blob column 2 { Q_ASSERT(label); // blob loading code break; } case 3: // the related column gets default treatment default: } } { switch(index.column()) { case 0: // do nothing special for column 0, 1 case 1: break; case 2: // do something special for blob column 2 { Q_ASSERT(label); // blob saving code break; } case 3: // the related column gets default treatment default: // so does anything we've missed } } };To copy to clipboard, switch view to plain text mode
Hello ChrisW67,
thanks a lot for your help. I've tried something like your code, and I've create my Delegate from your code, but, It seems don't work.
this is my code:
Qt Code:
{ Q_OBJECT public: { switch(index.column()) { case 9: // do something special for blob column 2 { Q_ASSERT(label); if (label) { QPixmap pixmap; if (pixmap.loadFromData(imageData)) label->setPixmap(pixmap); } break; } default: } } { switch(index.column()) { case 9: // do something special for blob column 2 { Q_ASSERT(label); if (label) { QBuffer buf; if (label->pixmap()->save(&buf)) model->setData(index, buf.data(), Qt::EditRole); } break; } default: // so does anything we've missed } } };To copy to clipboard, switch view to plain text mode
What do you think is the mistake?
Thanks a lot for your time
Michele
Which bit doesn't work? Doesn't compile? Doesn't update the QLabel mapped to column 9 (that's the tenth column)? Doesn't save a label image? Have you single stepped it? Is there valid data in the tenth column of the model?
Bookmarks