Results 1 to 3 of 3

Thread: [solved]Dynamically removing QPushButtons from Flowlayout

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Dynamically removing QPushButtons from Flowlayout

    Thank you for your reply.
    Unfortunately the proposed correction doesn't solve the problem.
    If I omit "flowlayout->update()" nothing in my program changes after I press the delete button (all Buttons remain in the flowlayout and all buttons still work). If I add "flowlayout->update()" to your correction, the program behaviour is the same as explained in the top post.

    I tried a bit more and now I have the behaviour I aimed for with:
    Qt Code:
    1. void MyWidget::deleteButton() {
    2.  
    3. QLayoutItem *item = flowlayout->takeAt(0);
    4.  
    5. if( item )
    6. {
    7. item->widget()->hide();
    8. delete item->widget();
    9. delete item;
    10. }
    11.  
    12. qDebug() <<"deleted: "<<flowlayout->count();
    13. }
    To copy to clipboard, switch view to plain text mode 

    delete item->widget(); makes the button disappear from the layout.
    item->widget()->hide(); makes sure that the buttons that are left get rearranged.
    Last edited by neff; 30th January 2013 at 15:44.

Similar Threads

  1. Replies: 6
    Last Post: 13th August 2011, 18:31
  2. Replies: 0
    Last Post: 27th October 2010, 15:57
  3. Where is my QPushButtons
    By HelloDan in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2009, 07:15
  4. Mouse Over Event on QPushButtons
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2007, 13:23
  5. Adding/removing widgets dynamically...
    By ReilenBlaeyze in forum Newbie
    Replies: 2
    Last Post: 16th February 2006, 10:55

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
  •  
Qt is a trademark of The Qt Company.