PDA

View Full Version : QSlider: changing the groove without changing the handle



Olivier Berten
28th November 2010, 20:31
Hi!

I wanted to modify the groove of a slider while keeping the original handler but it didn't seem to work...

If I just define the groove in the stylesheet, the groove looks as expected but the handle disappears...

Any hint?

QbelcorT
29th November 2010, 00:41
Hi,
It would be easier seeing a picture of what you are trying to do. I don't know if this helps or not but here is a stylesheet I used for my sliders ( I am using images for the groove and handle). Maybe it will give you some hints.


QSlider::groove:horizontal {border-image: url(icons:guage_cursor_bg1.png);
border-width: 1px; height: 31px;}
QSlider::handle:horizontal {margin-top:0px; margin-bottom:-1px;
image: url(icons:guage_cusor_n.png);

http://img560.imageshack.us/img560/2350/sliderk.png (http://img560.imageshack.us/i/sliderk.png/)

Olivier Berten
30th November 2010, 16:27
Well... Here is my code:
#!/usr/bin/env python
# coding: utf-8
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

app = QApplication(sys.argv)

style = """QSlider::groove:horizontal {
border: 1px solid #999999;
height: 8px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);
}
"""

slider = QSlider()
slider.setOrientation(Qt.Horizontal)
slider.setStyleSheet(style)

layout = QVBoxLayout()
layout.addWidget(slider)

widget = QWidget()
widget.setLayout(layout)
widget.show()

app.exec_()
and here is the result
5548

bisen
30th April 2013, 10:02
For most widgets, when you set stylesheet for one component, you may have to define stylesheets for other components too.

Like the QSlider, QScrollBar etc.

Here, defining both the groove and the handle in the stylesheet caused it to work.