[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] embedding iconic pushButton in TableView and/or TreeView
From:       James Polk <jpolk5001 () yahoo ! com>
Date:       2010-11-28 1:54:02
Message-ID: 498452.31466.qm () web38304 ! mail ! mud ! yahoo ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


>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



      
[Attachment #5 (text/html)]

<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: \
inherit;"><br>&gt;Just remember, that small self contained examples of such issues \
are the <br>&gt;ultimate weapon to engage them...<br>&gt;Pete<br><br>lol, \
totally,...I went back to Mark Summerfield's book again (and \
other<br>examples)...<br><br>I'm soooooo close...but still a step or two \
go...<br><br>Finally figured out how to use my delegate's "sizeHint" to adjust<br>the \
row height in a QTreeView..<br><br>&nbsp;&nbsp;&nbsp; def sizeHint(self, option, \
index):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fm = \
option.fontMetrics<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if index.column() == \
2:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # LongName, but could be any \
column #<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
text =  index.model().data(index)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
document = QTextDocument()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
document.setDefaultFont(option.font)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
return QSize(document.idealWidth() + 5, \
50)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return \
QStyledItemDelegate.sizeHint(self, option, index)<br><br>...the "50" being the height \
I needed for a 50x50 icon image in the<br>first column....<br><br>So,...it finally \
occurred to me that when MarkS says a delegate<br>can have "total control"...then \
that must mean everything must<br>pass thru the "paint" function...which strikes me \
as more of a filter<br>than a function,..but anyways...<br>Right now, I \
have<br><br>&nbsp;&nbsp;&nbsp; def paint(self, painter, option,  \
index):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if index.column() == \
0:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # \
Thumbnail<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
parent&nbsp;&nbsp; = \
self.parent()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
iconFile = index.model().data(index, \
Qt.DisplayRole)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
button&nbsp;&nbsp; = QPushButton("&amp;Icon", \
parent)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
icon&nbsp;&nbsp;&nbsp;&nbsp; = \
QIcon(iconFile)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
pixmap&nbsp;&nbsp; = icon.pixmap(QSize(50, 50) \
)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  button.setIcon(icon)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
painter.save()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
painter.drawPixmap(0, 0, 50, 50, pixmap \
)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
painter.restore()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
QStyledItemDelegate.paint(self, painter, option, index)<br><br>So, even though \
there's a PushButton definition in there, I still can't<br>get it to display at \
startup.&nbsp;&nbsp; I have been able though to define an<br>Icon and Pixmap, \
(passing the image filename from data() )<br>but painter only wants (it appears) to \
draw a pixmap, and not a<br>pushbutton...so I'm kinda' stuck there at the \
moment...<br>But I do have these pixmaps  showing at startup...so I'm think \
I'm<br>tantalizing close to a solution...<br><br>Now it might be,...that I may not \
absolutely need a pushbutton type..<br>I just need to enable the user that once they \
click on pixmap/button<br>that it would execute a function.&nbsp; Even that could be \
argued away<br>with,...by proving a RMB (rightmousebutton) pulldown menu in \
the<br>main view...Even so, I'd still like to understand and know how to do<br>the \
former,etc..<br><br>Anyways,...Any suggestions greatly appreciated...and Thanks \
again, Pete, for your help and \
interest,<br>Cheers,<br>-James<br></td></tr></table><br>

      



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic