Results 1 to 8 of 8

Thread: Add scrollbar in a QWidget,and change layout

  1. #1
    Join Date
    Jun 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Add scrollbar in a QWidget,and change layout

    Hi everybody,
    first,excuse me for the quality of my english,i am in a french speaking country.

    I have a QWidget wich contains images displayed vertically.
    I want to add a scroll in the widget and change the layout if the orientation of the widget change.I mean,if the widget is Horizontal,the images must be displayed horozontally,if the widget is vertical the image should be displayed vertically.

    The user can change the orientation by resizing.

    i hope that i was understood.

    Thank you.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Add scrollbar in a QWidget,and change layout

    You are looking for something like a flow layout, you may need to implement you own layout manger, see this Example
    It should be simple enough if you understand layout basics in Qt

    How is this post related to Qt Creator?

  3. #3
    Join Date
    Jun 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Add scrollbar in a QWidget,and change layout

    Thank you for your reply,
    I'll try your solution.

  4. #4
    Join Date
    Jun 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Add scrollbar in a QWidget,and change layout

    I have tried your solution,it solve the problem of layout but i have not possibility to add scrollbar in my
    qwidget object.

    How can i add a scollbar?

    Thank you again

  5. #5
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Add scrollbar in a QWidget,and change layout

    What about placing your widget in QScrollArea?

  6. #6
    Join Date
    Jun 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Add scrollbar in a QWidget,and change layout

    I have done this :

    Qt Code:
    1. this->setLayout(flowLayout);
    2. QScrollArea *scroll = new QScrollArea;
    3. scroll->setWidget(toolbox);
    4. scroll.show();
    To copy to clipboard, switch view to plain text mode 

    It display another frame,not in my actual frame

  7. #7
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Add scrollbar in a QWidget,and change layout

    I assume that flowLayout is your custom layout, so try this:

    QHBoxLayout *mainLayout = new QHBoxLayout;
    QScrollArea *area = new QScrollArea;
    QWidgte *widget = new QWidget;

    widget->setLayout(flowLayout);
    area->setWidget(widget);
    mainLayout->addWidget(area);
    setLayout(mainLayout);

    You also may need to set correct constraints on your flowlayout
    Last edited by Rachol; 21st June 2011 at 13:55.

  8. #8
    Join Date
    Jun 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Add scrollbar in a QWidget,and change layout

    I have tried your solution,but it does not work for me.

Similar Threads

  1. DockWidgetArea change and layout direction change
    By mstegehu in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2012, 21:24
  2. Qwidget and layout problem
    By ram4soft in forum Newbie
    Replies: 5
    Last Post: 16th March 2011, 06:19
  3. QWidget layout problems
    By MarkoSan in forum Newbie
    Replies: 3
    Last Post: 12th January 2010, 10:23
  4. layout QLabel and QWidget
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2010, 11:53
  5. Adding a scrollbar to a QWidget
    By qtUser500 in forum Newbie
    Replies: 13
    Last Post: 2nd September 2009, 19:48

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.