Qt-interest Archive, November 2006
QRadioButton indicator & setStyleSheet
Message 1 in thread
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?
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?
I'm trying this on machines running Fedora Core 5 &6
DS
--
[ signature omitted ]
Message 2 in thread
Hi David,
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 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.
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.
Girish
--
[ signature omitted ]
Message 3 in thread
Hi David,
David Scriven wrote:
>
> 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.
>
The documentation for the color option states: "The color used to render
text." Cannot get clearer than that :) But I agree that it would be nice
to use the color property to colorize the images for subcontrols. Please
make this suggestion this to qt-bugs@xxxxxxxxxxxxxx
> 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.
>
Yes, you need to generate an image for every state. Though a bit
cumbersome you get complete control over the appearance. Imagine the
recompilation cycles that style sheets save you from :)
> 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?
>
Hmm, I dont see the painting errors here. What QStyle and OS are you
running the program on?
> 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?
>
Today, you have to provide images of different colors. Hopefully, when
we have the "coloring" mechanism suggested above, Qt can make this simpler.
>> 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.
>
I agree. We will try to provide a svg file or something for Qt 4.3.
Please make this suggestion through qt-bugs.
Girish
--
[ signature omitted ]