[PyQt] embedding iconic pushButton in TableView and/or TreeView
James Polk
jpolk5001 at yahoo.com
Sun Nov 28 01:54:02 GMT 2010
>Just remember, that small self contained examples of such issues are the
>ultimate weapon to engage them...
>Pete
lol, totally,...I went back to Mark Summerfield's book again (and other
examples)...
I'm soooooo close...but still a step or two go...
Finally figured out how to use my delegate's "sizeHint" to adjust
the row height in a QTreeView..
def sizeHint(self, option, index):
fm = option.fontMetrics
if index.column() == 2: # LongName, but could be any column #
text = index.model().data(index)
document = QTextDocument()
document.setDefaultFont(option.font)
return QSize(document.idealWidth() + 5, 50)
return QStyledItemDelegate.sizeHint(self, option, index)
...the "50" being the height I needed for a 50x50 icon image in the
first column....
So,...it finally occurred to me that when MarkS says a delegate
can have "total control"...then that must mean everything must
pass thru the "paint" function...which strikes me as more of a filter
than a function,..but anyways...
Right now, I have
def paint(self, painter, option, index):
if index.column() == 0: # Thumbnail
parent = self.parent()
iconFile = index.model().data(index, Qt.DisplayRole)
button = QPushButton("&Icon", parent)
icon = QIcon(iconFile)
pixmap = icon.pixmap(QSize(50, 50) )
button.setIcon(icon)
painter.save()
painter.drawPixmap(0, 0, 50, 50, pixmap )
painter.restore()
else:
QStyledItemDelegate.paint(self, painter, option, index)
So, even though there's a PushButton definition in there, I still can't
get it to display at startup. I have been able though to define an
Icon and Pixmap, (passing the image filename from data() )
but painter only wants (it appears) to draw a pixmap, and not a
pushbutton...so I'm kinda' stuck there at the moment...
But I do have these pixmaps showing at startup...so I'm think I'm
tantalizing close to a solution...
Now it might be,...that I may not absolutely need a pushbutton type..
I just need to enable the user that once they click on pixmap/button
that it would execute a function. Even that could be argued away
with,...by proving a RMB (rightmousebutton) pulldown menu in the
main view...Even so, I'd still like to understand and know how to do
the former,etc..
Anyways,...Any suggestions greatly appreciated...and Thanks again, Pete, for your help and interest,
Cheers,
-James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20101127/0b4196c8/attachment.html>
More information about the PyQt
mailing list