Results 1 to 7 of 7

Thread: Adding widgets to QScrollArea

  1. #1
    Join Date
    Jan 2006
    Location
    Ukraine
    Posts
    5
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Adding widgets to QScrollArea

    Hi, guys.
    Need some help...
    The task is following: I need to place into QGroupBox some number of widgets - for example, QLabel. After filling this QGroupBox scrollbar must appear.
    Code is next:

    Qt Code:
    1. extGroupLayout = new QVBoxLayout;
    2. groupBoxLayout = new QVBoxLayout;
    3. scrollArea = new QScrollArea(this);
    4.  
    5. groupBox->setLayout(extGroupLayout);
    6. extGroupLayout->addWidget(scrollArea);
    7. scrollArea->setLayout(groupBoxLayout);
    8.  
    9. for(i=0;i<20;i++)
    10. {
    11. // Let's make our checkboxes...
    12. IDCheckbox[i] = new QCheckBox;
    13. groupBoxLayout->addWidget(IDCheckbox[i]);
    14. }
    To copy to clipboard, switch view to plain text mode 

    After executing, checkboxes get minimal possible height, ignoring value, set by setMinimalHeight method; last of them are hiding behind the edge of scroll area, but scrolling is still impossible

    Where is my problem? Don't say it is in my head
    Last edited by ser_bur; 16th May 2007 at 20:02.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding widgets to QScrollArea

    Do this:

    - Set this group box as the scroll area widget via QScrollArea::setWidget. You don't need to set a layout in the scroll area.
    - Add all the widgets you need to add to your group box.

    Be careful, because you may need to set some minimum sizes there ( for the scroll area, for example ).

    Regards

  3. #3
    Join Date
    Jan 2006
    Location
    Ukraine
    Posts
    5
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Unhappy Re: Adding widgets to QScrollArea

    Well, i tried, but result is the same. Main detail is that i must add widgets not directly to GroupBox, but to layout: real interface is much more complicated than just column of checkboxes, as in example. I think this is a reason... Is there a possibility to use layout in this case without "compressing" added widgets?..

    UPD: here is what i have at the moment:
    Last edited by ser_bur; 16th May 2007 at 20:45.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding widgets to QScrollArea

    You hould have this:

    QScrollArea <- QGroupBox <- a layout (whatever you need ) <- widgets ( created with the group box as parent and added to the layout ).

    You also should set the size of the group box to match the QScrollArea's viewport size.

    Regards

  5. The following user says thank you to marcel for this useful post:

    ser_bur (17th May 2007)

  6. #5
    Join Date
    Jan 2006
    Location
    Ukraine
    Posts
    5
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Unhappy Re: Adding widgets to QScrollArea

    After some playing with sizes, finally I've got scroll as expected . But height of widgets still stays minimal, ignoring CheckBox->setMinimumHeight() and groupBoxLayout->setRowMinimumHeight() methods

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding widgets to QScrollArea

    Make sure you created all the widgets with a parent ( the group box ).

  8. #7
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding widgets to QScrollArea

    Quote Originally Posted by ser_bur View Post
    After some playing with sizes, finally I've got scroll as expected . But height of widgets still stays minimal, ignoring CheckBox->setMinimumHeight() and groupBoxLayout->setRowMinimumHeight() methods
    Hi,

    can you please tell me how you did this? I want to implement same thing for my application.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

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.