[Qt-interest] custom shaped buttons

Pritam pritam_ghanghas at infosys.com
Wed Feb 8 08:02:50 CET 2012


On Tuesday 07 February 2012 09:48 PM, Carlos Smith wrote:
> 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.
Using stylesheet and doing your own paiting, is a tricky thing in qt. 
The biggest reason being QStyleSheetStyle is not public. This is the 
function which qt widgets use to get stylesheet palette.

<code>
// Polish palette that should be used for a particular widget, with 
particular states
// (eg. :focus, :hover, ...)
// this is called by widgets that paint themself in their paint event
// Returns true if there is a new palette in pal.
bool QStyleSheetStyle::styleSheetPalette(const QWidget* w, const 
QStyleOption* opt, QPalette* pal)
</code>

Have a look at qstylesheetstyle.cpp and qlineedit.cpp's paintevent. A 
temporary solution could be you introduce one more color Q_PROPERTY in 
your widget and set that as well from stylesheet using 
"qproperty-<propertyname>" syntax. Sorry I don't have a clean solution 
for your problem.
>
> 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.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>


-- 
Regards,
Pritam


**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are not 
to copy, disclose, or distribute this e-mail or its contents to any other person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has taken 
every reasonable precaution to minimize this risk, but is not liable for any damage 
you may sustain as a result of any virus in this e-mail. You should carry out your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***



More information about the Qt-interest-old mailing list