[Qt-interest] Drawing A Disabled QLabel Without Graying It

Malyushytsky, Alex alex at wai.com
Tue Apr 14 03:53:58 CEST 2009


Or you probably can use QAbstractButton instead of QLabel.
In this case you create Icon from your pixmap for Disabled mode.

I've used it in such way to create custom pixmaps for disabled buttons, when automatically grayed icon is ugly.

Regards,

Alex.




-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Nathan Carter
Sent: Monday, April 13, 2009 6:43 PM
To: qt-interest at trolltech.com List
Subject: Re: [Qt-interest] Drawing A Disabled QLabel Without Graying It


Can you consider using a QStackedWidget?  Just put the widget on one
pane, and put that pane on top when you want the widget "enabled"; put
the image on the other pane, and put that pane on top when you want
the widget "disabled".

Nathan


On Apr 13, 2009, at 9:30 PM, Karol Krizka wrote:

> Hi all,
>
> I'm wondering if it is possible to disable a QLabel, without it
> being drawn as
> grayed out.
>
> The reason I'm asking this is because I want to display a static
> image when
> one of my custom widgets is disabled. I am currently accomplishing by
> wrapping the custom widget in a parent QWidget and disabling the
> custom
> widget by disabling the parent QWidget. When the QWidget is
> disabled, it
> hides the custom widget and instead shows a QLabel with a pixmap. But
> since the parent QWidget is disabled, the QLabel is disabled too and
> draw in
> gray. It does not look too good in gray. So is there an attribute that
> disables this graying?
>
> If not, I thought about two other ways to implement what I described
> above,
> so I'm wondering if you have any other suggestions.
> 1) Override the setEnabled()/isEnabled() methods of the parent
> QWidget so
> they only change the status of the custom widget and not the parent
> QWidget.
> 2) Override the paintEvent() of the parent QWidget. If the widget is
> disabled,
> draw the image. If the widget is enabled, call QWidget::paintEvent()
> to draw
> as normally.
>
> --
> Cheers,
> Karol Krizka
> http://www.krizka.net
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list