PDA

View Full Version : Paint a scrollbar



humbleguru
6th January 2011, 17:48
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::paintEvent(). This is what I do:


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();
}

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.

tbscope
7th January 2011, 04:30
Note that you can also just use a scrollbar widget in a scene or item