Results 1 to 3 of 3

Thread: QScrollBar subclass constructor ignores orientation Qt4.4

  1. #1
    Join Date
    Jul 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QScrollBar subclass constructor ignores orientation Qt4.4

    I'm new to Qt so its probably me, but..

    I've created a trivial subclass of QScrollbar -

    Qt Code:
    1. class ScrollBar : public QScrollBar
    2. {
    3. Q_OBJECT
    4. public:
    5. ScrollBar ( Qt::Orientation orientation, QWidget * parent = 0 );
    6. protected:
    7. void paintEvent(QPaintEvent* event);
    8. };
    9.  
    10. ScrollBar::ScrollBar ( Qt::Orientation orientation, QWidget * parent )
    11. {
    12. QScrollBar::QScrollBar (orientation, parent);
    13. }
    14.  
    15. void ScrollBar:: paintEvent(QPaintEvent * event)
    16. {
    17. int x, y, w, h;
    18. this->rect().getRect(&x,&y,&w,&h);
    19. QScrollBar:: paintEvent(event);
    20. QPainter p(this);
    21. p.setPen(QPen(Qt::red,1));
    22. p.drawLine(x,y,x+w,y+h);
    23. }
    To copy to clipboard, switch view to plain text mode 

    when created by -
    Qt Code:
    1. scrollBar = new ScrollBar(orientation); // works for QScrollBar
    To copy to clipboard, switch view to plain text mode 
    a vertical scrollbar is drawn regardless of orientation.
    Following by -
    Qt Code:
    1. scrollBar->setOrientation(orientation); // not required for QScrollbar
    To copy to clipboard, switch view to plain text mode 
    provides a fix, but it wasn't needed when using the ancestor class.

    Where am I going wrong?
    Last edited by jpn; 24th July 2008 at 19:56. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QScrollBar subclass constructor ignores orientation Qt4.4

    It should be:
    Qt Code:
    1. ScrollBar::ScrollBar ( Qt::Orientation orientation, QWidget * parent )
    2. : QScrollBar::QScrollBar (orientation, parent)
    3. {
    4. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Jul 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollBar subclass constructor ignores orientation Qt4.4

    Thanks JP, my C++ is rusty

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.