[Qt-interest] QIcon behaves differently in Linux and Windows

Robert Hairgrove evorgriahr at hispeed.ch
Mon Jan 31 13:38:29 CET 2011


On 01/31/2011 12:54 AM, Marcelo Magno T. Sales wrote:
> Hello,
> 
> The code:
> 
> btnPicture->setEnabled(false);
> QIcon icon;
> icon.addPixmap(image, QIcon::Disabled);
> btnPicture->setIcon(icon);
> 
> produces different results in Linux and Windows. btnPicture is a
> QPushButton * and image is a QPixmap containing a colored image.
> When running this on Windows, btnPicture shows a colored icon as I would
> expect. However, when running on Linux, btnPicture shows an icon in
> shades of gray (?!) The QPushButton is disabled, but I have added the
> QPixmap to the QIcon specifying explicitly that the image should be used
> in the QIcon::Disabled mode and not in the QIcon::Normal mode. Is this a
> bug in QIcon or is there something subtle here I'm not seeing?
> 
> Thanks,
> 
> Marcelo

According to the documentation for QIcon:
"A QIcon can generate smaller, larger, active, and disabled pixmaps from
the set of pixmaps it is given. Such pixmaps are used by Qt widgets to
show an icon representing a particular action."

The second and third arguments to addPixmap are only used if you want to
add a different pixmap of your own for any particular Mode or State. The
documentation doesn't seem to state this explicitly, but I think you
need to set the Normal mode, too, before setting any of the others. I
haven't tried this, but you might need to set all four modes with custom
pixmaps in order to make the icon engine respect the colors.

Other than that, it sounds like it might be a bug in Qt. You might want
to file a bug report here: http://bugreports.qt.nokia.com.




More information about the Qt-interest-old mailing list