Results 1 to 7 of 7

Thread: Moving widgets within a layout.

  1. #1
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Moving widgets within a layout.

    I am using QVBoxLayout to have a vertical list of custom composite widgets which contain an up and down button, so to move that widget up and down within the list.

    It doesn't work.

    Do I have to delete and then recreate the widget in order to move it ?

    I have tried using layout->remove() and layout->insert() but it doesn't appear to be working.

  2. #2
    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: Moving widgets within a layout.

    I think using QLayout::takeAt() and QBoxLayout::insertWidget() should work.

  3. #3
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Moving widgets within a layout.

    Wow ! Fast reply !

    IIRC takeAt() is only in qt4, and so far I'm using qt3.

  4. #4
    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: Moving widgets within a layout.

    Oh, sorry for that. In your case use QBoxLayout::insertWidget() and QLayout::remove().

  5. #5
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Moving widgets within a layout.

    Just did that, and I am using ::findWidget(*QWidget) to get the widget index number, and it works at first, then it goes haywire.

    I have 3 sample widgets included, like this:

    startPosition.png
    and I can move number 2 up to the top by pushing the up button, like this:

    firstClick.png
    but if I try to move number 1 back to the top, I get no response. If I push the up button a second time, it doesn't move. In fact, if a push the up buttons a few times, none of them respond.

    I have not implemented the other buttons yet.

    Here is the relevant code (it is declared as a slot in the header). PositionElementLine inherits QWidget.

    Qt Code:
    1. void PositionElementBox::up(PositionElementLine *line)
    2. {
    3. int index = boxLayout->findWidget( line );
    4.  
    5. if(index > 0 ) //an index of 0 means the widget is at the top !!
    6. {
    7. boxLayout->remove(lineList.at(index));
    8. boxLayout->insertWidget( ( index - 1 ), line );
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by importantman; 26th May 2007 at 19:26. Reason: added images

  6. #6
    Join Date
    Mar 2006
    Posts
    17
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Moving widgets within a layout.

    oops! The error is in line 7. the lineList is copied from old code. should be

    ->remove(line);

  7. #7
    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: Moving widgets within a layout.

    Why not implement it as QTable and QTableItems and simply forget about the problem?

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. Promoted widgets and layout boxes
    By notsonerdysunny in forum Qt Tools
    Replies: 3
    Last Post: 2nd May 2007, 14:15
  3. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 22:54
  4. QtDesigner Layout Help
    By mentat in forum Qt Tools
    Replies: 5
    Last Post: 13th July 2006, 14:55
  5. "dynamic" layout
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2006, 07:16

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.