Results 1 to 3 of 3

Thread: QScrollArea with QGridLayout compress items and not show V Bar

  1. #1

    Default QScrollArea with QGridLayout compress items and not show V Bar

    Hi.

    I am trying to display many elements, derived widgets, in a frame.

    When I add just a few items scrollbar looks ok.
    but when adding more elements, more than real size elements are compressed and vertical scroll bar not appear.

    Qt Code:
    1. SearchResults::SearchResults(QWidget *parent) :
    2. QFrame(parent),
    3. ui(new Ui::SearchResults)
    4. {
    5. ui->setupUi(this);
    6.  
    7. gLayout = new QGridLayout(parent);
    8.  
    9. scrollWidget = new QWidget(parent);
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void SearchResults::setData()
    2. {
    3.  
    4. ui->scrollArea->setBackgroundRole(QPalette::Light);
    5.  
    6. int size = K_list::instance()->DetailList.size();
    7.  
    8. gLayout->setSpacing(10);
    9.  
    10. ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    11. ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    12.  
    13. resultWidget *rw[size];
    14. int cont;
    15. for(cont=0;cont<size;cont++)
    16. {
    17. rw[cont] = new resultWidget(this);
    18. rw[cont]->setData( K_list::instance()->DetailList.at(cont) );
    19. rw[cont]->connect();
    20. gLayout->addWidget(rw[cont]);
    21. // appear compressed
    22. }
    23.  
    24. ui->scrollArea->setWidget(scrollWidget);
    25.  
    26. scrollWidget->setLayout(gLayout);
    27.  
    28. show();
    29. }
    To copy to clipboard, switch view to plain text mode 


    Thanks for any advice
    Attached Images Attached Images

  2. #2

    Default Re: QScrollArea with QGridLayout compress items and not show V Bar

    I found the solution.
    Thanks God.

    The problem was the UI has not set, Layout Manager and Size Policies was unset.
    I choose fixed for all elements.

  3. #3
    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: QScrollArea with QGridLayout compress items and not show V Bar

    I don't think the problem is really there. You are doing very weird combinations with the layout - first you set it on the parent of the current widget (which should trigger a warning if the widget already has a layout) then you add widgets to it and then you set it as a layout of the child widget. Anyway, setting the "widgetResizable" property of the scroll area to true should solve the problem regardless of size policies used.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Compress
    By chethana in forum Newbie
    Replies: 14
    Last Post: 25th April 2012, 15:14
  2. QGridLayout: how to know it has finished rendering items?
    By slash_blog in forum Qt Programming
    Replies: 0
    Last Post: 8th June 2010, 13:06
  3. Can't click menubar items / QPixMap doesn't show
    By richardander in forum Qt Programming
    Replies: 1
    Last Post: 30th December 2008, 11:45
  4. Delete a QGridLayout and New QGridLayout at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 14:01
  5. Replies: 2
    Last Post: 11th September 2007, 09:57

Tags for this Thread

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.