Results 1 to 5 of 5

Thread: Scrollbar covers Labels in ScrollArea

  1. #1
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Scrollbar covers Labels in ScrollArea

    Hi,

    I have a ScrollArea with many groupboxes which contain Checkboxes. But it seems like the size of the ScrollArea does not adapt to the layout.
    Qt Code:
    1. QVBoxLayout* verticalLayout[NumberOfAvailableTypes];
    2. QVBoxLayout* verticalLayoutForWidget = new QVBoxLayout(ui->AvailableDataScrollArea);
    3. ui->scrollAreaWidgetContents->setLayout(verticalLayoutForWidget);
    4.  
    5. QGroupBox *TypeGroupBox[NumberOfAvailableTypes];
    6.  
    7. for (int i = 0; i < NumberOfAvailableTypes; i++){
    8. TypeGroupBox[i] = new QGroupBox(ui->AvailableDataScrollArea);
    9. TypeGroupBox[i]->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
    10. TypeGroupBox[i]->setTitle(AllData.at(i)->NameWithoutNumber());
    11. verticalLayout[i] = new QVBoxLayout(TypeGroupBox[i]);
    12.  
    13. QCheckBox *DataCheckbox[AllData.at(i)->quantity()];
    14. QHBoxLayout* horizontalLayout[AllData.at(i)->quantity()];
    15.  
    16. for (int j = 1; j <= AllData.at(i)->quantity(); j++){
    17. DataCheckbox[j] = new QCheckBox(TypeGroupBox[i]);
    18. DataCheckbox[j]->setText(AllData.at(i)->NameWithNumber());
    19.  
    20. horizontalLayout[j] = new QHBoxLayout();
    21. horizontalLayout[j]->addWidget(DataCheckbox[j]);
    22. verticalLayout[i]->addLayout(horizontalLayout[j]);
    23. }
    24. }
    25. verticalLayoutForWidget->addWidget(TypeGroupBox[i]);
    26. }
    27. verticalLayoutForWidget->addSpacerItem(new QSpacerItem(40,20,QSizePolicy::Minimum, QSizePolicy::Expanding));
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Scrollbar covers Labels in ScrollArea

    The scroll bar adapts to the size of the content widget (scrollAreaWidgetContents I assume) but that size is not changing here. Packing widget into its layout will, in general, not change the containers size. Try setting the vertical size policy of scrollAreaWidgetContents to Fixed so it is forced to match the aggregate of the contents vertical size hints.

  3. #3
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Scrollbar covers Labels in ScrollArea

    SizePolicy of scrollAreaWidgetContents is horizontal and vertical: fixed now

    SizePolicy of ScrollArea is horizontal: preferred; vertical: expanding

    sizeAdjustPolicy: AdjustToContens

    When I set the horizontal ScrollBar ScrollBarAsNeeded it seems to work. But I dont want to have a horizontal ScrollBar. I want the ScrollArea to expand horizontal when it's layout changes.

  4. #4
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Scrollbar covers Labels in ScrollArea

    It still does not work.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Scrollbar covers Labels in ScrollArea

    You want the QScrollArea to abandon its reason for existing and grow to accomodate its content. That is precisely what it is designed not to do. The scroll area gets the space allocated to it by its parent layout/widget and allows you to display an arbitrary sized widget within that space, using scrollbars as needed.

    To defeat the default behaviour you have to do the work. When the contentsWidget() changes size you must manually change (force) the horizontal dimension of the QScrollArea to accomodate the contained widget's width plus a margin and width for a vertical scroll bar if one is present.

Similar Threads

  1. Replies: 0
    Last Post: 4th August 2015, 09:12
  2. How to control scrollbar in scrollarea ?
    By lwz in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2014, 14:18
  3. Filling area covers curve。
    By lwz in forum Qwt
    Replies: 6
    Last Post: 24th August 2014, 08:57
  4. Replies: 0
    Last Post: 14th April 2010, 22:26
  5. Get covers from amazon.com like in Amarok
    By jiveaxe in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2008, 08:29

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.