[Interest] QIcon on/off doesn't work on QAction

Sensei senseiwa at gmail.com
Tue Jul 2 13:14:08 CEST 2013


Dear all,

I currently use a multiple QPixmap on a single QIcon to make the current 
button visible in a QButtonGroup. I use the following code:


// Colorize!
QIcon& colorize(const QString& pix)
{
     QPixmap orig(pix), blue(orig.size());
     blue.fill(QColor(64 - 32, 160 - 32, 255 - 32));
     blue.setMask(orig.createMaskFromColor(Qt::transparent));

     QIcon *i = new QIcon();
     i->addPixmap(blue, QIcon::Normal, QIcon::On);
     i->addPixmap(orig, QIcon::Normal, QIcon::Off);

     return *i;
}

// Set the icon: it works perfectly
toolbutton->setIcon(colorize(":/icons/do.png"));



The code above works perfectly. A selected button is blue, an inactive 
one is gray (the normal icon).

However, setting the icon in a QAction embedded in a QToolBar, doesn't:



action = new QAction(colorize(":/icons/add_file.png"), QString(), this);
connect(action, SIGNAL(triggered()), this, SLOT(test()));
toolbar->addAction(action);



Is there something I'm missing?

Might it be the color of the icon (dark gray) that can influence this 
behavior?



Thanks!



More information about the Interest mailing list