PDA

View Full Version : style sheets



alisami
6th May 2009, 10:36
hi,

I'm trying to modify the style sheet of some widgets. the problem is that, when I modify a property of the widget, all the other properties are gone.

for example when I modify the border of a groupbox with the following "QGroupBox {border: 1px}" the border-radius is resetted etc. When I modify the border of a QComboBox, all the color information is gone.

I am using the plastique style and I want to modify only some certain properties and leave the rest as it is ? Is there a way to do so ?

Sami

spirit
6th May 2009, 10:49
it seems like you override old style sheet by new one. you have to whole style sheet or set style sheet for each widget separately.

zgulser
6th May 2009, 10:57
alisami meraba,

Spirit is right, whenever you attempt to write for example;

QComboBox* myComboBox;

myComboBox->setStyleSheet( "background: red"); // background is red now

myComboBox->setStyleSheet(" border-width: 2px; border-style:outset"); // background is not red now but borders are set

namely, setStyleSheet is overidden by the lastly executed one. So you are supposed to wrtie the whole in one.

wagmare
6th May 2009, 10:58
here in QProgressBar i want to change the style sheet of two items in progressBar()
1, progressBar
2, progressBar::chunk

so to use this two properties separately .. the last stylesheet override my previous one ..
so i use both in a single stylesheet settings ,
setStyleSheet(" QProgressBar {border: 1px solid grey; border-radius:5px;} QProgressBar::chunk {background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 #C71585, stop: 1 white);}");

just a space ' ' between the two stylesheet properties ... now both were working fine ..

alisami
6th May 2009, 15:13
hello again,

what I wanted to ask was, is it possible to set only the border of a widget like
QComboBox:border {blablabla}.

but I guess there is no such way to do so.

thanks for the replies,
sami

Lykurg
6th May 2009, 15:22
Of course there is a way, but your example
border: 1px; is the wrong CSS syntax for only changing the border width. Use
border-width: 1px;instead. Not proved with Qt but should work.

zgulser
6th May 2009, 15:25
Hi,

what's wrong with doing "QComboBox { border-width:1px; border-style: outset; border-color: red}" ?

Are you trying to do it from the source or designer by the way?

alisami
7th May 2009, 10:31
actually I experienced this problem when I changed the QGroupBox main style.
when that style is changed, the QGroupBox::title's padding is gone, so I had to modify it.

the above can be observed by just putting the following style sheet in the designer to a widget:
QGroupBox
{
border-width: 1px;
border-color: #FF0000;
border-radius: 1px;
}

actually I started thinking that I am missing a point about the style sheets.

alisami
7th May 2009, 10:41
Hi,

what's wrong with doing "QComboBox { border-width:1px; border-style: outset; border-color: red}" ?

Are you trying to do it from the source or designer by the way?
the problem is that, I only want to change the border width. if I only specify the `border-width` nothing happens. I should also enter the `border-style` and `border-color` as well to see the border of the combo box.

again, what I want to do is to only modify the border-width of any widget without entering the other parameters.

I again tried in the designer but didn't manage to success.