Results 1 to 5 of 5

Thread: Delete widgets from QVBoxLayout

  1. #1
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Delete widgets from QVBoxLayout

    Hi,
    I am creating a QWidget in the constructor and adding that QWidget to QScrollArea. When the verticall scroll bar reaches to the maximum value, i am creating another QWidget and adding to the existing widget. All these are in vertical layout.

    I want to delete all the widgets in the vertical layout created dynamically when i press a button.

    My code :

    writingArea is a another class.
    writingArea::writingArea(QWidget *parent) :
    QWidget(parent){ //constructor of writingArea class//}

    //Declaration
    MainWindow.h

    writingArea *writewidget;
    QVBoxLayout *vwritelayout;

    //Constructor of MainWindow.h

    writewidget = new writingArea;
    writewidget->setMinimumSize(1000,1300);
    vwritelayout->addWidget(writewidget);
    connect(ui->answerarea_scrollArea->verticalScrollBar(),SIGNAL(actionTriggered(int)), this,SLOT(add_write_area()));
    connect(ui->pushbutton,SIGNAL(clicked()),this,SLOT(delete_wid gets()));

    //Functions
    void MainWindow::add_write_area()
    {


    int write_sliderval = ui->answerarea_scrollArea->verticalScrollBar()->maximum();
    int write_sliderpos=ui->answerarea_scrollArea->verticalScrollBar()->sliderPosition();

    if(write_sliderval == write_sliderpos)
    {
    writewidget = new writingArea;
    writewidget->setMinimumSize(1000,1300);
    vwritelayout->addWidget(writewidget);
    }
    }
    void Mainwindow::delete_widgets()
    {

    //Here I want to delete the widgets created in veritelayout.

    }

    Please help me....

  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: Delete widgets from QVBoxLayout

    Qt Code:
    1. while(!vertilayout->isEmpty()) {
    2. delete vertilayout->takeAt(0);
    3. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Delete widgets from QVBoxLayout

    Its not coming inside the while loop

  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: Delete widgets from QVBoxLayout

    Apparently you have nothing in the layout.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Delete widgets from QVBoxLayout

    Then the layout contains no items and you don't need to do anything.

Similar Threads

  1. delete runtime-created widgets causes crash
    By jonasbalmer in forum Qt Programming
    Replies: 5
    Last Post: 10th February 2010, 22:36
  2. Replies: 4
    Last Post: 19th February 2009, 12:10
  3. QScrollView with a QVboxlayout
    By rishid in forum Newbie
    Replies: 1
    Last Post: 18th January 2008, 17:14
  4. Disappearing widgets in QVBoxLayout
    By torleifs in forum Newbie
    Replies: 1
    Last Post: 24th October 2007, 14:17
  5. Replies: 2
    Last Post: 22nd February 2006, 15:58

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.