PDA

View Full Version : Unable to change height of the handle of QSlider



Cupidvogel
25th October 2015, 09:50
I am trying to design a QSlider where I need to vary the height of the slider handle based on certain parameters. This is what I have so far:



QSlider *fScrollbar = new QSlider(this);
fScrollbar->setGeometry(280,5,10,400);
fScrollbar->setMinimum(5);
fScrollbar->setMaximum(50);
fScrollbar->setTracking(true);
fScrollbar->setStyleSheet("QSlider::handle:vertical { width: 190px; background: black; }");


This is not working as expected, the handle still defaults to a small height which is not changing. This is what which is appearing:

11470

How do I make it work?

ChrisW67
25th October 2015, 20:14
Surely you want to change the height of the vertical slider handle, not the width.

Cupidvogel
25th October 2015, 20:29
Sorry, my bad. Yes, I am changing the height of the handle for vertical scrollbar. I was experimenting with horizontal scrollbar as well, I posted that code by mistake. Same result in both cases.

anda_skoa
26th October 2015, 08:10
My guess is that the height of a vertical slider handle is tightly controlled by the style plugin or even by the slider itself since it is also used as the indicator how long the scrollable range is.

Cheers,
_

Cupidvogel
26th October 2015, 08:30
That makes sense. I thought as much. But I found of plenty of websites where it says that this is the way the height of te handle can be varied, so I thought perhaps I am doing something wrong.

ChrisW67
26th October 2015, 20:23
It is also possible that to customise a part of QSlider you must customise some other parts or all of it. The examples always seem to customise the groove and handle together:
http://doc.qt.io/qt-4.8/stylesheet-examples.html#customizing-qslider

Cupidvogel
3rd November 2015, 18:32
Yep, that is possible. Will try it out. Thanks!