[Interest] QIcon not actually generating variations for QToolButton?

David M. Cotter dave at kjams.com
Wed Sep 11 04:31:56 CEST 2019

all my "icons" are created in code.
they start life as QImage (possibly programmatically drawn), converted to QPixMap, then to QIcon.

so i get my QIcon, and set it into my QToolButton with toolButtonP->setIcon(pix);

says in the doc:
> The simplest use of QIcon is to create one from a QPixmap file or resource, and then use it, allowing Qt to work out all the required icon styles

so i thought the "pushed down" state (drawn slightly darker) (as in when the user clicks on the button) would be generated on the fly for me.

if that's not the case, i can easily generate a darker image, but then how do i programmatically add it into QIcon as the "down state" so it's used by QToolButton?

here's the code i use to set the icon up:

> CPixels		pix(picNameStr); // loads correctly, trust me
> QIcon		qIcon;
> qIcon.addPixmap(pix, QIcon::Normal);
> CPixels		darkPix(pix);	// deep copy, trust me
> darkPix.Lighten(-0.2f);		// negative is "darken" (20%)
> qIcon.addPixmap(darkPix, QIcon::Active);
> toolButtonP->setIcon(qIcon);

however, when the user clicks the button (button otherwise set up empty in Designer), no darken'd version appears (appears not to be tracking the mouse down)

here's the thread on the forum with some pokes at it but no answer:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190910/641d2838/attachment.html>

More information about the Interest mailing list