PDA

View Full Version : Hide a slider on a QScrollBar



paolom
5th October 2009, 14:28
Hi...

I've a scroll bar to view a certain numbers of widgets...

but it's possible that the widgets are few and I don't need to scroll...for this I want to hide the slider on a QScrollBar...whitout hide all the QScrollBar...


is it possible??

Thanks

yogeshgokul
5th October 2009, 14:55
You need to set the Qt::ScrollBarPolicy property to Qt::ScrollBarAsNeeded value.

paolom
5th October 2009, 14:56
No...I don't want to hide the whole scroll bar....

I need to hide only the SLIDER under certain conditions!

Is it possible?!

yogeshgokul
5th October 2009, 15:07
Oops.
Ok, that could be done, you need to subclass QscrollBar and need to hide the Slider manually. Checking the size of viewport with scroll area in paint event will do the trick. The main thing is to find out the point where you want to hide slider. But hiding the slider is just a function call.

paolom
5th October 2009, 15:09
Yes...I can call the hide() function of the slider...

but there aren't any functions (nether on the QScrollBar ot the QAbstractSlider class) to get the pointer of the slider widget...

how can I do this?!

yogeshgokul
6th October 2009, 07:05
Gotcha !
Now you left with 3 more options.
1. Use QStyle and hide the sub control QStyle::SC_ScrollBarSlider.
2. Use StyleSheet and hide the handle, something like this:

QScrollBar::handle:horizontal {
width: 0px;
height: 0px;
}

3. Subclass QScrollBar and stop the painting of slider.

StyleSheet option is easiest. ;)

paolom
6th October 2009, 10:00
Thanks for your solution!!!

I've solved with another solution:

setEnable(false)

when I doesn't need the slider.

I thought about more solution but the simplest is often the best!! :) :)

yogeshgokul
6th October 2009, 10:02
Doesn't it looks ugly, a disabled scroll bar? Then why don't you better hide it?

paolom
6th October 2009, 10:07
Doesn't it looks ugly, a disabled scroll bar? Then why don't you better hide it?

I've used the setStylesSheet to make my custom scrollBar.

After, in this class, I've a method like this:


void MPScrollBar::setSlider(int iPageStep)
{
if(iPageStep==0)
{
setEnabled(false);
}
else
{
setEnabled(true);
setPageStep(iPageStep);
setSingleStep(pageStep());
}
}

to disable the scrollbar when the argument is 0.

I can tell you sincerely that when I disable the scrollbar it doesn't look ugly...