PDA

View Full Version : Qt 4.3 Style sheet, new features



Angelo Moriconi
8th June 2007, 16:06
Hi all !

I'm playing with the new widgets, pseudo-states and sub-controls added in qt 4.3, since the documentations is still lacking I have some questions.

1) I cannot find a way to define style sheet for the QScrollBar widget, I try redefining its sub-controls.. without any results, someone have made also a simple test ?

2) I have a problem to define the style sheet for a vertical QSlider, the horizontal one code that I use is:


QSlider::groove:horizontal
{
border-image: url(qss/sl_groove.png) 1;
border-width: 1;
height: 1px;
}

QSlider::handle:horizontal
{
image: url(qss/h_handle.png);
top: -6px;
}

the vertical one works visually but I cannot move the handle (it is blocked) (probably something in the code is missing):


QSlider::groove:vertical
{
border-image: url(qss/sl_groove_v.png) 1;
border-width: 1;
}

QSlider::handle:vertical
{
image: url(qss/v_chandle.png);
}

3) I don't understand how to set the style sheet of a generic widget (suppose QSlider) and then setting a different style sheet only for a custom widget class derived from the generic one (i.e a ColorSlider that inherit QSlider). The code that I use, without any good result have this form:

QSlider {
......
}

ColorSlider {
......
}

I try to use also several types selector, and I can made a distinction only using the ID Selector (defining the ObjectName for the widget). I would like to define different style sheet for different kind of widgets.

Best,

Angelo

Angelo Moriconi
12th June 2007, 11:36
Dear all,
anyone has tried to style a QScrollBar ?
I tried different combinations without any good result (also using QDesigner to make the test faster).
I would like to have some code snippets or some little example...

Thanks in advance,

Angelo

jens
12th June 2007, 16:22
Here is how you can style a normal vertical scrollbar. It is not pretty, but I'm sure with some border images it can be tailored according to your taste. :D



QScrollBar::vertical {
background:lightgray;
border-color:black;
border-style:dotted;
width: 15px;
margin-top:16px;
margin-bottom:16px;
}

QScrollBar::add-page:vertical,
QScrollBar::sub-page:vertical {
background: none;
}

QScrollBar::add-line:vertical{
height: 14px;
background:darkGray;
subcontrol-origin: margin;
subcontrol-position: bottom;
border-color:black;
border-style:solid;
border-width:1px;
}

QScrollBar::sub-line:vertical {
subcontrol-origin: margin;
subcontrol-position: top;
height: 14px;
background:darkGray;
border-color:black;
border-style:solid;
border-width:1px;
}

QScrollBar::handle:vertical {
background:red;
min-height: 20px;
background:gray;
border-color:black;
border-style:solid;
border-width:1px;
}

QScrollBar::add-line:pressed,
QScrollBar::sub-line:pressed,
QScrollBar::handle:pressed{
background:lightgray;
}