Hi! I'm trying to paint a scrollbar in a QGraphicsItem by calling QStyle::drawComplexControl(). It works like a charm for vertical scrollbars. However, it doesn't work properly for horizontal scrollbars in some styles, especially in the oxygen style.
I have made a simple test case by reimplementing QWidget:
aintEvent(). This is what I do:
{
option.minimum = 0;
option.maximum = 50;
option.orientation = Qt::Horizontal;
option.pageStep = 10;
option.singleStep = 1;
option.sliderPosition = 0;
option.sliderValue = 0;
option.
activeSubControls = QStyle::SC_None;
option.
subControls = QStyle::SC_All;
option.
state = QStyle::State_Enabled;
option.
rect = QRect(0,
0,
200,
16);
style
()->drawComplexControl
(QStyle::CC_ScrollBar,
&option,
&painter
);
event->accept();
}
void paintEvent(QPaintEvent *event)
{
QStyleOptionSlider option;
option.minimum = 0;
option.maximum = 50;
option.orientation = Qt::Horizontal;
option.pageStep = 10;
option.singleStep = 1;
option.sliderPosition = 0;
option.sliderValue = 0;
option.activeSubControls = QStyle::SC_None;
option.subControls = QStyle::SC_All;
option.state = QStyle::State_Enabled;
option.rect = QRect(0, 0, 200, 16);
QPainter painter(this);
style()->drawComplexControl(QStyle::CC_ScrollBar, &option, &painter);
event->accept();
}
To copy to clipboard, switch view to plain text mode
Am I missing something? Should I do it in a different way?
Notice in the screenshots how it's totally screwed up in the Oxygen style while it displays fine in Plastique. In Windows, the buttons show up/down arrows instead of left/right arrows. If you change it to Qt::Vertical (and give a proper size) it displays fine in all those styles.
Added after 13 minutes:
I answer to myself: I had to add QStyle::State_Horizontal to the state.
Bookmarks