Results 1 to 3 of 3

Thread: "dynamic" layout

  1. #1
    Join Date
    Feb 2006
    Location
    Magdeburg
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy "dynamic" layout

    hi all

    I am trying to produce a dynamic layout. That means i want a layout with some buttons in a row. The number of the buttons should change regarding to the number of elements in a hash. I am trying this for days, but it never looks like i want it to look. I am not able to change the number of buttons without seeing the old buttons, which should be deleted. Here is my code and some screenshots:


    This is my first approach. Its only a test without real values. First I remove all buttons from the layout (if there are some). I then add 3 buttons regarding to knownClients is empty or not. It looks like in picture "before.jpg" when 3 buttons are inserted. If knownClients is empty there should be nothing, but in fact there still are some buttons displayed. Please look at "after1.jpg".

    Qt Code:
    1. //.h-File:
    2.  
    3. QHBoxLayout *justAlayout;
    4.  
    5.  
    6. //.cpp-File:
    7.  
    8. ShowClientList::ShowClientList() : QWidget() {
    9. justAlayout = new QHBoxLayout;
    10. setLayout(justAlayout);
    11. }
    12.  
    13. void ShowClientList::showClients() {
    14. QLayoutItem *child;
    15. if ((child = justAlayout->takeAt(1)) != 0) { delete child; }
    16. justAlayout->update();
    17.  
    18. QPushButton *pb1 = new QPushButton ("asdf");
    19. QPushButton *pb2 = new QPushButton ("qwert");
    20. QPushButton *pb3 = new QPushButton ("dada");
    21.  
    22. if (!knownClients.isEmpty()) {
    23. justAlayout->addWidget(pb1);
    24. justAlayout->addWidget(pb2);
    25. justAlayout->addWidget(pb3);
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 




    My second approach is similar to the first one. I only added 3 lines of code to delete the layout after deleting all members of the layout. Then I assing a new layout before inserting the buttons. With 3 buttons inserted its looks the same, but after deleting them it looks like in picture "after2.jpg". The buttons are shifted down and are still clickable.

    Qt Code:
    1. delete this->layout();
    2.  
    3. justAlayout = new QHBoxLayout;
    4. setLayout(justAlayout);
    To copy to clipboard, switch view to plain text mode 



    Is there a possibility to manage this problem and display the right number of buttons correctly?

    Hulk
    Attached Images Attached Images

  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: "dynamic" layout

    How about this?
    Attached Files Attached Files

  3. The following 2 users say thank you to wysota for this useful post:

    hulk (9th May 2006), Smudge (5th January 2007)

  4. #3
    Join Date
    Feb 2006
    Location
    Magdeburg
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "dynamic" layout

    thanks a lot. It works!

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 21:21
  2. Qt like Layout Manager available for .NET platform
    By vkhaitan in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 14:36
  3. Replies: 2
    Last Post: 9th July 2008, 23:28
  4. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 18:11
  5. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 23:54

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.