Results 1 to 3 of 3

Thread: QGridLayout in a QScrollArea - scrollbars do not appear

  1. #1
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGridLayout in a QScrollArea - scrollbars do not appear

    Hi,

    I have a QScrollArea on my UI and I would like to put several things into it that would be lareger than the actual size of the scrollarea. So I defined a gridlayout into it and I put just some labels for testig.

    My problem is clearly to be seen on the image attached. If the size of the scrollarea is smaller than the content then the content appears compressed (slided onto each other). However I would prefer to have a fixed sized gridlayout that is in this scrollarea and the scrollbars would appear if needed.

    Here is the useful code part for this:
    Qt Code:
    1. this->gl = new QGridLayout;
    2. this->lala = new QLabel[9]; // lala stands for "layout's label" :)
    3. for(int i = 0; i < 3; i++)
    4. {
    5. for(int j = 0; j < 3; j++)
    6. {
    7. //setup the actual lala[]
    8. lala[3*i + j].setText(QString::number(3*i + j));
    9. lala[3*i + j].setFrameStyle(1);
    10. lala[3*i + j].setLineWidth(1);
    11. lala[3*i + j].setMinimumSize(100,100);
    12. lala[3*i + j].setAlignment(Qt::AlignCenter);
    13.  
    14. //add lala[] to the gridlayout
    15. gl->addWidget(&lala[3*i + j],i, j ,1,1,Qt::AlignCenter);
    16. }
    17. }
    18. for(int i = 0; i < 3; i++)
    19. {
    20. gl->setColumnMinimumWidth(i,100); // no effect
    21. gl->setRowMinimumHeight(i,100); // no effect
    22. }
    23.  
    24. ui->scrollArea_2->setLayout(gl);
    To copy to clipboard, switch view to plain text mode 

    1. why does setColumnMinimumWidth and setRowMinimumHeight has no effect?
    2. how can I achieve this: the scrollbars sould appear below minimum sizes instead of collapsing?

    Or should I use a completely other solution?

    Szilvi
    Attached Images Attached Images
    Szilvi

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGridLayout in a QScrollArea - scrollbars do not appear

    Set a widget to the scroll area, not a layout. Then it should work.

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

    szisziszilvi (3rd August 2011)

  4. #3
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGridLayout in a QScrollArea - scrollbars do not appear

    so this is it:
    this->w = new QWidget;
    w->setLayout(gl);
    ui->scrollArea_2->setWidget(w);
    Szilvi

Similar Threads

  1. Scrollbars for QStackedLayout
    By JohannesMunk in forum Newbie
    Replies: 0
    Last Post: 6th December 2009, 16:50
  2. scrollbars and qgraphicsview
    By captiva in forum Qt Programming
    Replies: 13
    Last Post: 20th February 2009, 12:00
  3. QGraphicsView and scrollbars
    By godmodder in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2008, 22:34
  4. Delete a QGridLayout and New QGridLayout at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 13:01
  5. How to get scrollbars in QTreeWidget
    By Arthur in forum Qt Programming
    Replies: 14
    Last Post: 5th May 2006, 21:51

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.