Disable slider of scrollbar in scrollarea
-
Hi all,
Is it possible to disable the slider of a scrollbar in a scroll area?
I've styled the scrollbar using css to show the arrows next to the slider. I did this by setting a width on the scrollbar, and using margins to make the slider more narrow. While this looks good, now the margin itself also responds to drag/click events. This is not what I want.
Is there any way to disable the slider, or make the slider respond to a smaller area?
Thanks in advance!
-
@AlexanderB
Are you looking forQt::ScrollBarAlwaysOff
link . -
No, the scrollbar is needed, I only want the arrows to respond to events, not the slider.
-
@AlexanderB
Hi
You could apply an event filter to the scrollbars
(via https://doc.qt.io/qt-5/qabstractscrollarea.html#horizontalScrollBar)
and eat those "clicks" that are outside your wanted area.
or you could subclass QScrollBar and override mouse event function
to alter how mouse press works.You can disable the scrollbars with
ui->scrollArea->horizontalScrollBar()->setEnabled(false);
ui->scrollArea->verticalScrollBar()->setEnabled(false);but that prevents any clicking.
-
That sounds useful! Now I'm wondering how to detect the correct area. The public API doesn't really help me, but perhaps I'm missing something obvious.
The "actionTriggered" event seems to happen after updated the position, but before updating the UI. At his point I've already lost the current position (unless I use the "valueChanged" signal to keep track. But I hope there is an easier way to do this..
Thanks again!
-
Hi
If you look here
https://code.woboq.org/qt5/qtbase/src/widgets/styles/qwindowsstyle.cpp.htmlin 1894
void QWindowsStyle::drawComplexControlyou can see the use of
QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget);I assume you can get the various parts this way, even you changed it using stylesheet.