[PyQt] Override QStyledItemDelegate.initStyleOption not working?

Andreas Pakulat apaku at gmx.de
Tue Jan 10 20:19:18 GMT 2012


On 10.01.12 10:19:13, Phil Thompson wrote:
> On Tue, 10 Jan 2012 00:11:49 +0100, Andreas Pakulat <apaku at gmx.de> wrote:
> > Hi,
> > 
> > I'd like to customize the display of a model via a styleditemdelegate,
> > in particular I want to add a decorating icon depending on some custom
> > role from the model.
> > 
> > As far as I can see the easiest way to do this would be overriding
> > initStyleOption since then I can set the icon and icon-size directly on
> > the option and leave the rest to the standard paint etc. methods.
> > 
> > Unfortunately it seems this does not work in PyQt, the code is executed
> > properly but the icon does not show up in the itemview. Since the
> > function in C++ takes a pointer to the option-parameter I wonder wether
> > this is simply not possible with PyQt or wether I need to go hunting for
> > the bug elsewhere?
> > 
> > Using Qt 4.7.4, sip 4.13  and PyQt 4.8.6
> 
> Are you keeping a reference to the option - if not see if this makes a
> difference.

Unfortunately no, I've written up a small example for what I'm trying to
do and attached it.

I've also tried overriding paint(), calling initStyleOption there, then
calling the parent paint() function and the icon is set on the option
parameter in between, but the icon is not painted in the gui...

Andreas
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: styleditemdelegate.zip
Type: application/zip
Size: 3163 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120110/67e48742/attachment.zip>


More information about the PyQt mailing list