[Qt-interest] custom shaped buttons
Carlos Smith
CSmith at stonewedge.net
Tue Feb 7 17:18:58 CET 2012
Thanks, maybe I am missing something, but the problem I had is that I cannot find the corresponding palette entry for the pressed color I set in the style sheet.
I had debug code that dumped the RGB's for every color in the QPalette::ColorRole enumeration, like this:
QStyleOptionButton opt;
initStyleOption(&opt);
QPalette palette = opt.palette;
QBrush tempBrush;
tempBrush = palette.color(QPalette::Active, QPalette::Window);
qDebug() << "Window color" << tempBrush.color().red() << tempBrush.color().green() << tempBrush.color().blue();
tempBrush = palette.color(QPalette::Active, QPalette::WindowText);
qDebug() << "WindowText color" << tempBrush.color().red() << tempBrush.color().green() << tempBrush.color().blue();
And none of the colors was the one I had set for the "pressed" state. Though the same stylesheet declaration worked for standard QPushbuttons. If I recall I traced all the way down and they (Qt) had the color somehow, but I couldn't get it from the application level.
I would have expected the opt.palette to have been loaded with the colors corresponding to the current (pressed) state. I know of no other palette to use. For that matter, the bevel draws correctly with the "pressed" state background color, but I can't get the foreground/text/window color to use to draw my custom text. Hence I use a custom property in the style sheet to get the functionality I want, which is a real kludge.
Thanks,
Carlos
-----Original Message-----
From: qt-interest-bounces+csmith=stonewedge.net at qt.nokia.com [mailto:qt-interest-bounces+csmith=stonewedge.net at qt.nokia.com] On Behalf Of Ross Bencina
Sent: Tuesday, February 07, 2012 4:43 AM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] **JUNK** Re: custom shaped buttons
On 7/02/2012 4:46 PM, Tibo W wrote:
> QStyleOptionButton opt;
> initStyleOption(&opt);
[snip]
> Unfortunately, there doesn't seem to be any way to extract the style for > the button "pressed" state from the palette, it simply doesn't seem to > be there, though it is magically available in Qt's own pushbutton > renderer.
I'm pretty sure you'll find it in the style option "state" field.
According to the docs for QStyle::State the QStyle::State_Sunken bit should be set.
http://developer.qt.nokia.com/doc/qt-4.8/qstyle.html#StateFlag-enum
if( opt.state & QStyle::State_Sunken )
... button is pressed ...
Ross.
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
This electronic message is intended only for the use of the individual or entity named above and may contain information which is privileged and/or confidential. If you are not the intended recipient, be aware that any disclosure, copying, distribution, dissemination or use of the contents of this message is prohibited. If you have received this message in error, please notify the sender immediately.
This electronic message is intended only for the use of the individual or entity named above and may contain information which is privileged and/or confidential. If you are not the intended recipient, be aware that any disclosure, copying, distribution, dissemination or use of the contents of this message is prohibited. If you have received this message in error, please notify the sender immediately.
More information about the Qt-interest-old
mailing list