Results 1 to 3 of 3

Thread: Horizontal scrollbar problem

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

    Default Horizontal scrollbar problem

    Hi,

    I am trying to place a horizontal scrollbar in the bottom of a widget. The widget in question is one of (3) panes in a splitter window.

    The first problem I discovered was that the scrollbar is too long for the width of the window by 62 units.

    This code is in the constructor of my widget class.
    Qt Code:
    1. mpScrollbar = new QScrollBar ( Qt::Horizontal, this );
    2. mpScrollbar->setGeometry ( 0, height() + 20, width() - 62, 20 );
    To copy to clipboard, switch view to plain text mode 

    The second problem is that when I resize the window, the scrollbar does not resize with it.

    I tried overriding the widget's resizeEvent but when I do, the scrollbar is NEVER drawn.

    Qt Code:
    1. void MyWidget::resizeEvent ( QResizeEvent * event )
    2. {
    3. mpScrollbar->setGeometry ( 0, height() + 20, width() - 62, 20 );
    4. mpScrollbar->update();
    5. }
    To copy to clipboard, switch view to plain text mode 

  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: Horizontal scrollbar problem

    How about QScrollArea? Or at least use layouts if you want to handle a QScrollBar by hand...
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    blaylockr (22nd July 2008)

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

    Default Re: Horizontal scrollbar problem

    Thanks for the suggestion. I finally got it to work using your suggestion.

    At first, it put the scrollbar in the middle of the widget with this code:
    Qt Code:
    1. mpScrollbar = new QScrollBar ( Qt::Horizontal, this );
    2. QVBoxLayout *layout = new QVBoxLayout;
    3. layout->addWidget(mpScrollbar);
    To copy to clipboard, switch view to plain text mode 
    Then I added arguments to the addWidget function:
    Qt Code:
    1. layout->addWidget(mpScrollbar,0,Qt::AlignBottom);
    To copy to clipboard, switch view to plain text mode 

    Still wasn't quite right. Had margins around it, so I added the following line:
    Qt Code:
    1. layout->setMargin(0);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Treeview scrollbar not updating when inserting rows
    By Khal Drogo in forum Qt Programming
    Replies: 11
    Last Post: 29th November 2007, 13:13
  2. GraphicsView/GraphicsScene: scrollbar policy Qt::ScrollBarAsNeeded
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2007, 13:15
  3. about scrollbar style
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 13:34
  4. Horizontal scrollbar tracking problem
    By tebessum in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2006, 23:15
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.