First. Your code should create a memory leak. Cause addAction will make a copy of icon and you never delete result of colorize Look at declaration: QAction **addAction <qtoolbar.html#addAction-5>* ( const QIcon & *icon*, const QString & *text*, const QObject * *receiver*, const char * *member* )Second. You did not clarify what "does not work" means. Anyway my guess you should either set use QToolbar::setIconSize to the size of your pixmap or add compatible (by size ) pixmap to your icon. The icons you are using are definitely not compatible with default toolbar icon sizes, so at the best the enabled icon is auto scaled, then greyed and that what you may see, at the wrse you see no icon at all ( sorry too lazy to test).
Regards, Alex On Tue, Jul 2, 2013 at 4:14 AM, Sensei <sense...@gmail.com> wrote: > 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! > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest