Results 1 to 8 of 8

Thread: Container widget with scrollbars

  1. #1
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Container widget with scrollbars

    Hello!
    I need to place variable amount of widgets (buttons for example) on
    another widget. In case amount of childs is too much to display at
    once, parent should provide scrollbars.
    I use flow layout from qt examples (customlayout example) and that's
    why QScrollView can't help (I don't know how it can) me. It just squeezes flow layout to one column.
    I also tried simple QFrame as container. Flow layout on it works well but when all widgets can't be displayed at once it provides no scroll bars and scrapes outer layout. (see figs http://dteslenko.googlepages.com/qtinterest-1-ok.png and http://dteslenko.googlepages.com/qtinterest-1-bad.png)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Container widget with scrollbars

    How do you try to use the scrollview with flow layout?

  3. #3
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Container widget with scrollbars

    Quote Originally Posted by wysota View Post
    How do you try to use the scrollview with flow layout?
    Just as it has been told in docs:
    Qt Code:
    1. QScrollView * sv = new QScrollView( this );
    2. QVBox * b = new QVBox(sv->viewport());
    3. sv->addChild(b);
    To copy to clipboard, switch view to plain text mode 
    after it I working with b : I create layout in it and widgets with b as parent.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Container widget with scrollbars

    Maybe you should create the layout directly on the viewport without the need to use QVBox (using QWidget would be better here anyway)?

    Could you provide a compilable example of the widget? I'll play with it a little to see why the outer layout doesn't work.

  5. #5
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Container widget with scrollbars

    Here it is! You can add more *.png files in the project directory to make problem more obvious.
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Container widget with scrollbars

    Use this:
    Qt Code:
    1. QScrollView * sv = new QScrollView( this );
    2. QWidget * w = new QWidget(sv->viewport());
    3. w->setPaletteBackgroundColor(Qt::white);
    4. sv->addChild(w);
    5. sv->setResizePolicy(QScrollView::AutoOneFit);
    To copy to clipboard, switch view to plain text mode 

    The magic line is the resize policy, which causes your widget to be resized to the viewport size. The result is fine, but not perfect. Something is messed up with the widget height, but I didn't want to get into the code too deep. I'm sure you'll manage to fix it. It's probably caused by heightForWidth in the layout.

  7. The following user says thank you to wysota for this useful post:

    a550ee (28th September 2006)

  8. #7
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Container widget with scrollbars

    Big thanks, wysota!

  9. #8
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Container widget with scrollbars

    Hi,
    Well going forward with the similar kind of requirement,in all the reference material also I could find was a situation where there was only single widget and the scroll bar was applied to whole window, my requirement is a little different , I need scroll bar for only half of the visible area, for e.g. my window is divided in to 2 panels and I want a scroll bar only in the right hand side panel, provided the text in the panel is large. I am trying by using a widget for right hand panel and then applying QScrollArea, but no luck so far. Can anybody please help me ?

    Thanks
    Anju

Similar Threads

  1. Container Extensions
    By mariok in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2007, 11:06
  2. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 06:57
  3. Replies: 4
    Last Post: 24th March 2006, 22:50
  4. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16
  5. advanced split widget
    By vitaly in forum Qt Programming
    Replies: 10
    Last Post: 24th January 2006, 20:00

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.