Qt-interest Archive, November 2006
[Fwd: Re: QRadioButton indicator & setStyleSheet]
Message 1 in thread
Forwarding response per David's request
-------- Original Message --------
Subject: Re: QRadioButton indicator & setStyleSheet
Date: Thu, 2 Nov 2006 09:39:00 -0800 (PST)
From: David Scriven <davidwriter@xxxxxxxxx>
To: girish@xxxxxxxxxxxxx
Girish Ramakrishnan wrote:
>>David Scriven wrote:
>> I'm trying to create a radiobutton that is purple when unchecked, green when checked. I tried using
>> setStyleSheet so:
>>
>> setStyleSheet("QRadioButton::indicator:checked{ image: url(radiobutton.png); color:green;} \
>> QRadioButton::indicator:unchecked {image: url(radiobutton.png); color:purple}");
>>
>> and placed this in the constructor of the widget (a descendent of QDialog) containing the
>> radiobuttons, but nothing happens - the images remain resolutely uncoloured. Of course
>> I could paint the images beforehand (eg. greenchkradiobutton.png), but that seems to defeat
>> the point. What am I doing wrong?
>>
>"color" changes the color of the radio button text. "image" gives an
>image for the indicator for each state. You need to provide separate
>colorized images if you want different colors for different states. (Why
>does that defeat the point btw?)
It is not clear from the write-up that if you are trying to alter a
sub-control you MUST (at least for radio buttons) supply an image of the
sub-control else you get nothing. Changing the text color was easy, but
that's not what I want to do.
I assumed that you could alter a subcontrol color using the style sheet
- if you can't (and this is again not made clear) then you have to
generate an image for every state/style/subcontrol option - again not
made clear. The 'point' is that it seems (at least from my reading) that
you can change the colour of sub-controls using the colour option -
which apparently one cannot do.
If I don't include the image I get a whole lot of QPainter error
messages (fair enough - it's trying to paint nothing) - I would have
thought that while it was painting the image it could change the colour?
This arises from porting an SGI app where the buttons do have different
colours depending various parameters. Since the SGI style has been
dropped in Qt4 (and I'm not sure it would have worked the way I wanted,
since I've never used Qt3) I'm modifying the Motif style and thought
setStyleSheet would make it easy.
>> It seems that if you want to do something to a sub-control, Qt requires that you supply an
>> image of that sub-control - this is an irritation if all you want to change is the colour. Again,
>> is there a way around this? If not, is there a source for the sub-control images for each of the
>> types and styles?
>>
>This is the case because the QStyle on your platform may not be able to
>render purple indicators.
or green ones, or any other color! If other apps can do it why not Qt?
>Have a look at examples/widgets/stylesheet. In the menu, file->edit
>style. Check out the "Pagefold" style which has images for each
>radiobutton state.
>BTW, Tools like Inkscape make creation of these images very trivial.
While no doubt true, it would be nice to have a Qt-supplied library of
sub-control images for the various styles/states so that you can
generate images consistent with the style that you are using - it
would be easier than starting from scratch.
David
--
[ signature omitted ]