Results 1 to 8 of 8

Thread: How to remove widget added in runtime?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to remove widget added in runtime?

    Hi,
    i'm working on a database application; i would like to add the possibility for the user to perform custom query with AND/OR clauses. So i thought to add to my program 2 button, one for adding and one for removing clauses; each clause is a custom widget; the list of clause/widget is stored in a QList. The remove function should delete the last added clause from QList and from gui. My problem is I can't remove widgets from the gui after adding them. Here is some code of a sample application i made for the thread (no database handling):

    Qt Code:
    1. MainDialog::MainDialog(QWidget *parent)
    2. :QDialog(parent)
    3. {
    4. ...
    5. groupBox = new QGroupBox("Clauses");
    6. ...
    7. groupBoxLayout = new QVBoxLayout(groupBox);
    8. ...
    9. removeConditionButton->setEnabled(false);
    10. ...
    11. connect(addConditionButton, SIGNAL(clicked()), this, SLOT(addCondition()));
    12. connect(removeConditionButton, SIGNAL(clicked()), this, SLOT(removeCondition()));
    13. }
    14.  
    15. void MainDialog::addCondition()
    16. {
    17. QComboBox *comboBox = new QComboBox;
    18. groupBoxLayout->addWidget(comboBox);
    19. list.append(comboBox);
    20. removeConditionButton->setEnabled(true);
    21. }
    22.  
    23. void MainDialog::removeCondition()
    24. {
    25. list.removeLast();
    26. if(list.size() == 0)
    27. removeConditionButton->setEnabled(false);
    28. }
    To copy to clipboard, switch view to plain text mode 

    What have I to add to removeCondition()? Or is there a better solution?

    Thanks
    Last edited by jiveaxe; 1st November 2007 at 10:29. Reason: spelling error
    Giuseppe CalÃ

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.