Results 1 to 4 of 4

Thread: Move QtLayout with child widgets

  1. #1
    Join Date
    Jul 2014
    Location
    Germany
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Move QtLayout with child widgets

    Hello!

    Is it possible (easily) to move an layout (QHBoxLayout) with child elements (QButton and QComboBox) from an QGridLayout into another layout (here an QVBoxLayout)?

    I tried an grid_layout->removeItem(x) and an vbox_layout->insertItem(1,x), but it does not work.
    Any ideas?

    Regards
    Sven

  2. #2
    Join Date
    Jul 2008
    Posts
    405
    Thanks
    9
    Thanked 52 Times in 50 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Move QtLayout with child widgets

    Hi, which part does not work? Removing or inserting?
    Have you tried calling update() after the operation?

    Ginsengelf

  3. #3
    Join Date
    Jul 2014
    Location
    Germany
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Move QtLayout with child widgets

    Hello!

    The code compiles and there is no error during execution.
    Here some code:

    Qt Code:
    1. QGridLayout* const glayout = dynamic_cast<QGridLayout*>(form->layout());
    2. if (glayout)
    3. {
    4. QLayoutItem* const last_item = glayout->itemAtPosition(glayout->rowCount()-1, 0);
    5.  
    6. if (last_item && dynamic_cast<QHBoxLayout*>(last_item))
    7. {
    8. qDebug() << "Moving...";
    9. glayout->removeItem(last_item);
    10. ui->verticalLayout_frame_edit->insertItem(1, last_item);
    11. }
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Should this be enough to move the layout with all its children or do I have to do something special
    to move the children too?

    And I tried several "update()" calls...

    Regards
    Sven
    Last edited by SvenA; 17th June 2019 at 10:08.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,535
    Thanks
    13
    Thanked 1,576 Times in 1,505 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Move QtLayout with child widgets

    The widgets that the layout controls the positioning for are children of the widget that layout was applied to, not the layout itself. If the two layouts are not in the same parent widget then you will need to consider this as well.

Similar Threads

  1. Replies: 1
    Last Post: 17th December 2018, 12:18
  2. Implicitly move child widgets *on their own.*
    By tescrin in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2012, 17:22
  3. Child widgets
    By poporacer in forum Newbie
    Replies: 6
    Last Post: 12th August 2010, 03:04
  4. Replies: 5
    Last Post: 18th April 2010, 23:31
  5. Child widget does not move along with its parent
    By starch in forum Qt Programming
    Replies: 8
    Last Post: 9th July 2009, 12:35

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.