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

Karol Krizka kkrizka at gmail.com
Tue Apr 14 03:30:13 CEST 2009


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



More information about the Qt-interest-old mailing list