[PyQt] table model and pixmap
Scott Frankel
frankel at circlesfx.com
Wed Sep 10 01:11:00 BST 2008
Hello,
If anyone has an idea on how to resolve the buggy delegate behavior I
mention below, I'd great appreciate it!
Thanks!
Scott
On Sep 9, 2008, at 10:03 AM, Scott Frankel wrote:
>
> Hello,
>
> Looking at documentation for the QSqlRelationalDelegate class, I've
> hacked my way through to displaying a pixmap in a table view, though
> it's buggy.
>
> Hopefully, someone will be able to suggest solutions or
> documentation/examples to fix the following:
>
> - at launch, the fields display the path strings to the images,
> instead of the images themselves
> - on double-clicking, the fields suddenly display the images (hurray!)
> - on making any other mouse-click selections in the table, all data
> (image, text string, &c.) vanish (???)
>
>
> My ThumbnailDelegate class follows below.
>
> Thanks in advance!
> Scott
>
>
>
>
> class ThumbnailDelegate(QtSql.QSqlRelationalDelegate):
>
> def __init__(self, parent=None):
> super(ThumbnailDelegate, self).__init__(parent)
>
>
> def paint(self, painter, option, index):
> QtSql.QSqlRelationalDelegate.paint(self, painter, option, index)
>
>
> def createEditor(self, parent, option, index):
> if index.column() == THUMBNAIL:
> editor = QtGui.QLabel(parent)
> return editor
> else:
> return QtSql.QSqlRelationalDelegate.createEditor(self, parent,
> option, index)
>
> def setEditorData(self, editor, index):
> if index.column() == THUMBNAIL:
> imageStr = index.model().data(index,
> QtCore.Qt.DisplayRole).toString()
> imageMap = QtGui.QPixmap(QtCore.QString(self.tr(imageStr)))
> editor.setPixmap(imageMap)
> else:
> QtSql.QSqlRelationalDelegate.setEditorData(self, editor, index)
>
>
> def setModelData(self, editor, model, index):
> if index.column() == THUMBNAIL:
> model.setData(index, QtCore.QVariant(editor.text()))
> else:
> QtSql.QSqlRelationalDelegate.setModelData(self, editor, model,
> index)
>
>
>
>
> On Sep 8, 2008, at 9:56 PM, Scott Frankel wrote:
>
>>
>> Hello,
>>
>> Can anyone point me to documentation &/or examples for setting
>> pixmaps in a table view that gets its data from a table model?
>>
>> I have a table view I populate from a QSqlRelationalTableModel
>> instance. One of the model's data fields is an absolute path to
>> small thumbnail images on disk. I'd like to intercept the model's
>> data for the image paths and paint the images as pixmaps in one of
>> the columns of cells of the table view.
>>
>> Thanks in advance!
>> Scott
>>
>>
>> _______________________________________________
>> PyQt mailing list PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>
>
>
>
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
More information about the PyQt
mailing list