Results 1 to 3 of 3

Thread: destroy QHBoxLayout

  1. #1
    Join Date
    Mar 2011
    Posts
    51
    Qt products
    Qt3 Qt4 Qt/Embedded
    Thanks
    7

    Default destroy QHBoxLayout

    hello ever one here is my code i am calling all these statements in my button event handler like this

    Qt Code:
    1. void analysis::on_pushButton_clicked()
    2. {
    3. myplot * p = new myplot(gao.structpayloadgraph,gao1.structpayloadgraph, gao.structcol-2, "payload");
    4.  
    5. myplot * p1 = new myplot(gao.structsessiongraph,gao.structsessiongraph ,gao.structcol-2, "session");
    6.  
    7.  
    8. QHBoxLayout * layout = new QHBoxLayout;
    9. ui->horizontalLayout_2->addLayout(layout);
    10. layout->addWidget(p);
    11. layout->addWidget(p1);
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    myplot is graph plotting class but the problem is that each time i click the button new graph appear and previous remains, like one !st click 2 appear on second they become 4 then 6...... how to i destroy QHBoxLayout in my button event handler

    thanks

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: destroy QHBoxLayout

    Not sure why you are adding layout to another layout. Add all the plots to a container widget, and delete the container widget as an when required, like this

    Qt Code:
    1. analysis {
    2. ...
    3. private:
    4. QWidget * container;
    5. }
    6.  
    7. void analysis::analysis()
    8. {
    9. container= 0;
    10. }
    11.  
    12. void analysis::on_pushButton_clicked()
    13. {
    14. if(container)
    15. delete container;
    16.  
    17. myplot * p = new myplot(gao.structpayloadgraph,gao1.structpayloadgraph, gao.structcol-2, "payload");
    18. myplot * p1 = new myplot(gao.structsessiongraph,gao.structsessiongraph ,gao.structcol-2, "session");
    19.  
    20. QHBoxLayout * layout = new QHBoxLayout;
    21. layout->addWidget(p);
    22. layout->addWidget(p1);
    23. container->setLayout(layout);
    24.  
    25. ui->horizontalLayout_2->addWidget(container);
    26. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2011
    Posts
    51
    Qt products
    Qt3 Qt4 Qt/Embedded
    Thanks
    7

    Default Re: destroy QHBoxLayout

    thanks u sir i wrote
    Qt Code:
    1. while(!ui->horizontalLayout_3->isEmpty())
    2. { QWidget * w = ui->horizontalLayout_3->takeAt(0)->widget();
    3. delete w;
    4. }
    To copy to clipboard, switch view to plain text mode 

    and it worked for me thanks for your help

Similar Threads

  1. How to destroy an object right
    By Cruz in forum Newbie
    Replies: 7
    Last Post: 22nd January 2009, 20:43
  2. Object Not destroy
    By Sudhanshu Sharma in forum Qt Programming
    Replies: 3
    Last Post: 31st July 2008, 00:16
  3. [QDockWindow] destroy
    By villy in forum Qt Programming
    Replies: 8
    Last Post: 1st December 2006, 12:06
  4. Destroy() function
    By lewis in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2006, 20:55
  5. Replies: 1
    Last Post: 24th June 2006, 21: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.