Results 1 to 2 of 2

Thread: Paint a scrollbar

  1. #1
    Join Date
    Jan 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Paint a scrollbar

    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:

    Qt Code:
    1. void paintEvent(QPaintEvent *event)
    2. {
    3. option.minimum = 0;
    4. option.maximum = 50;
    5. option.orientation = Qt::Horizontal;
    6. option.pageStep = 10;
    7. option.singleStep = 1;
    8. option.sliderPosition = 0;
    9. option.sliderValue = 0;
    10. option.activeSubControls = QStyle::SC_None;
    11. option.subControls = QStyle::SC_All;
    12. option.state = QStyle::State_Enabled;
    13. option.rect = QRect(0, 0, 200, 16);
    14.  
    15. QPainter painter(this);
    16. style()->drawComplexControl(QStyle::CC_ScrollBar, &option, &painter);
    17.  
    18. event->accept();
    19. }
    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.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by humbleguru; 6th January 2011 at 17:48.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Paint a scrollbar

    Note that you can also just use a scrollbar widget in a scene or item

Similar Threads

  1. How to add scrollbar...?
    By jojanpm in forum Qt Programming
    Replies: 4
    Last Post: 25th October 2010, 18:51
  2. ScrollBar
    By damodharan in forum Qt Programming
    Replies: 1
    Last Post: 11th February 2010, 14:50
  3. QToolBox scrollbar
    By paolom in forum Qt Programming
    Replies: 0
    Last Post: 21st October 2009, 11:27
  4. Using Scrollbar mainwindow
    By Amit_3117 in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2009, 16:57
  5. Scrollbar
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2007, 07:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.