[PyQt] embedding iconic pushButton in TableView and/or TreeView

Hans-Peter Jansen hpj at urpla.net
Sat Nov 27 18:50:59 GMT 2010

On Thursday 25 November 2010, 03:33:28 James Polk wrote:
> Woooohooooo....I got a custom delegate installed....at least
> partially, lol... Using the basic QItemDelegate
> I've first tried a comboBox, which seems a little more
> straightforward,..

Congrats, James. The world isn't as bad as it feels sometimes ;-)

> When using QTableView,...the "index.column()" calls want text
> matching the column headings,...but in QTreeView, the same call wants
> an integer index#...so my code looks like...
>   def createEditor(self, parent, option, index):
>       if index.column() == 0:         # Thumbnail
>               button = QPushButton(parent)
>               return button
>       if index.column() == 4:         # Format
>               comboBox = QComboBox(parent)
>               comboBox.addItem("ma")
>               comboBox.addItem("mb")
>               comboBox.addItem("obj")
>               comboBox.setEditable(True)
>               return comboBox
>       return QItemDelegate.createEditor(self, parent, option, index)
> I was all in celebration mode,...until I began to add the initial
> pushbutton/icon in the first column.....Right now, I'm just using
> QPushButton and will add the image/pixmap later...
> Well..the danged curious thing is....that when I run the code,
> and double-click on the cells of the first column, the custom
> delegate dutifully returns a nice PushButton....but my conundrum
> is that I still can't figure out how to add the PushButton to the
> QTreeView on startup!...<sigh>....

You need a item delegate, then.

> You may recall the data layout I'm going for is something like...
> 1     [icon1]       data       data      data    etc  
> 2     [icon2]       data       data      data    etc
> 3       etc
> 4       etc
> ...and later,...when a user binks on the icon, it will need to
> execute a command...
> So,...some progress, but still more jungle ahead,lol...<sigh>
> Maybe I'll go reread your stardelegate code again ;-)

Just remember, that small self contained examples of such issues are the 
ultimate weapon to engage them...


More information about the PyQt mailing list