Results 1 to 2 of 2

Thread: Layout objects reusable?

  1. #1
    Join Date
    Mar 2011
    Posts
    82
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Layout objects reusable?

    I was wondering if it was possible to use same layout objects (a QHBoxLayout, i.e) to define the layout of different objects.

    E.g.


    Qt Code:
    1. QHBoxLayout * boxLayout;
    2. QGridLayout * gridLayout;
    3.  
    4. QGroupBox * group1;
    5. QGroupBox * group2;
    6. QGroupBox * group3;
    7.  
    8. QComboBox * comboBox1;
    9. QComboBox * comboBox2;
    10. QComboBox * comboBox3;
    11.  
    12. QLabel * label1;
    13. QLabel * label2;
    14. QLabel * label3;
    15.  
    16. //-------------------
    17.  
    18. gridLayout->addWidget(label1);
    19. gridLayout->addWidget(comboBox1);
    20.  
    21. groupBox->setLayout(gridLayout);
    To copy to clipboard, switch view to plain text mode 

    and then do somethingl ike gridLayout->clear(); and reuse that layout.

    My problem is that I've found myself in need of nested layouts inside 3 GroupBoxes and it would be rather annoying to triple the ammount of objects (once for every GroupBox) just because of it.

    Thanks for your help.

  2. #2
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Layout objects reusable?

    I think it's possible ,but every time you re-parent your layout to a new widget a previous one will lose it and...become blank.Maybe it's fine if you're gonna have one visible widget at any moment (like with QStackedLayout).

Similar Threads

  1. QGraphicsScene and QGraphicsWidget (reusable and embeddable)
    By OriginalCopy in forum Qt Programming
    Replies: 17
    Last Post: 4th April 2011, 18:03
  2. Replies: 0
    Last Post: 12th December 2010, 05:09
  3. Replies: 3
    Last Post: 9th January 2010, 15:47
  4. Replies: 0
    Last Post: 25th May 2009, 10:00
  5. Replies: 7
    Last Post: 18th July 2006, 21:33

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.