Results 1 to 8 of 8

Thread: QGridLayout place new widgets at top

  1. #1
    Join Date
    May 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default QGridLayout place new widgets at top

    hi,

    how is it possible to add new widgets at top in a grid layout? I like to fill it up dynamic, but after i add the first i would like to at the second at the row 1...

    anybody an idea?

    greez

  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: QGridLayout place new widgets at top

    Does that mean you don't want to arrange them layout, one over the other?

    Create the child widgets with parent (one which contains the layout), and don't add to layout.
    Last edited by Santosh Reddy; 8th June 2011 at 20:06. Reason: updated contents

  3. #3
    Join Date
    May 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGridLayout place new widgets at top

    more in detail at the moment i have a list (vector) contains the objects. this list will be grow while the application runs. because i don't want to rearrange all the object in the layout i just add the last one:

    Qt Code:
    1. vector<Object> list = someObjects;
    2.  
    3. for (int i = lastCount; i < list.size(); i++){
    4. QLabel *label= new QLabel();
    5. label->setText(list[i]->toString());
    6. lastCount++;
    7. ((QGridLayout*) ui.view->layout())->addWidget(label, i, 0);
    8. ui.view->repaint();
    9. }
    To copy to clipboard, switch view to plain text mode 

    however i like to arrange them so:

    third object
    second object
    first object

    thx
    Last edited by rouge; 8th June 2011 at 21:21. Reason: updated contents

  4. #4
    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: QGridLayout place new widgets at top

    This may not possible with QGridLayout, you need you write a custom Layout Manager.

    Oee alternate way which you can try is to create all the QLabels upfront (with null strings), and populate the text, as the applciation gorws. (you should know the number of QLabels upfront). This is not a good practle solution though.

  5. #5
    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: QGridLayout place new widgets at top

    Have you tried simply adding new widgets to row 0 of the layout?
    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.


  6. #6
    Join Date
    May 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGridLayout place new widgets at top

    Have you tried simply adding new widgets to row 0 of the layout?
    Yes i tried this...but its only override the first row...

  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: QGridLayout place new widgets at top

    You better use QVBoxLayout, then you can use the insertWidget method

  8. #8
    Join Date
    May 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGridLayout place new widgets at top

    Thx for the help...the best way i find is to use a QTreeWidget.

Similar Threads

  1. Repositioning widgets in QGridLayout
    By Rayven in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2011, 15:30
  2. Replies: 2
    Last Post: 16th December 2010, 12:52
  3. Widgets in QGridLayout placed at top left
    By anarion in forum Newbie
    Replies: 2
    Last Post: 2nd September 2010, 16:06
  4. space between widgets in qgridlayout
    By demol in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2010, 21:07
  5. How correct to place widgets in QMdiSubWindow
    By sawerset in forum Qt Programming
    Replies: 0
    Last Post: 16th April 2009, 00:49

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.