Slider action area of a QScrollbar
I'm customizing the scrollbars style of my application and I'm having trouble determining the slider's area of action. If I'm not wrong this should be done in the QStyle :: subControlRect method, with the QStyle :: SC_ScrollBarGroove subcontrol.
According to the Qt documentation on QStyle :: SC_ScrollBarGroove: "Special sub-control which contains the area in which the slider handle may move".
Well, I create the 2 rectangles according to whether the horizontal or vertical scrollbar avoiding the squares of the arrows (up, down, left, right) and that in this way the slider stops when they reach those squares. As it seems that something I do wrong because the slider reaches the end of the scrollbar by covering the squares of the arrows.
Hi and welcome to devnet,
You should show your code, that will make things easier to get help.
I'm at home and I don't have the code in front of me but it was something like that:
case SC_ScrollBarGroove: if (scrollbar->orientation == Qt::Horizontal) result.setRect(16, 0, scrollbar->rect.width()-32, scrollbar->rect.height()); else result.setRect(0, 16, scrollbar->rect.width(), scrollbar->rect.height()-32); break;
This code is in QStyle :: subControlRect method. To set the QRect for the arrow buttons i have other case clauses with QStyle::SC_ScrollBarAddLine and QStyle::SC_ScrollBarSubLine. The width of the arrow buttons for the horizontal scrollbar is 16, the same for the height for the vertical scrollbar. I also have more case clauses for the space between the slider and arrow buttons with QStyle::SC_ScrollBarAddPage and QStyle::SC_ScrollBarSubPage.
I have to say that the arrow buttons and the spaces between these and the slider is correct. The only problem is with the action area of the slider, that doesn't begin where the arrow button ends, but starts from the beginning of the scrollbar.
Thank you for your reply ;-)
One thing I'd say is fishy with your code is that you are using absolute coordinate rather than take into account the surroundings.