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):
MainDialog
::MainDialog(QWidget *parent
){
...
...
...
removeConditionButton->setEnabled(false);
...
connect(addConditionButton, SIGNAL(clicked()), this, SLOT(addCondition()));
connect(removeConditionButton, SIGNAL(clicked()), this, SLOT(removeCondition()));
}
void MainDialog::addCondition()
{
groupBoxLayout->addWidget(comboBox);
list.append(comboBox);
removeConditionButton->setEnabled(true);
}
void MainDialog::removeCondition()
{
list.removeLast();
if(list.size() == 0)
removeConditionButton->setEnabled(false);
}
MainDialog::MainDialog(QWidget *parent)
:QDialog(parent)
{
...
groupBox = new QGroupBox("Clauses");
...
groupBoxLayout = new QVBoxLayout(groupBox);
...
removeConditionButton->setEnabled(false);
...
connect(addConditionButton, SIGNAL(clicked()), this, SLOT(addCondition()));
connect(removeConditionButton, SIGNAL(clicked()), this, SLOT(removeCondition()));
}
void MainDialog::addCondition()
{
QComboBox *comboBox = new QComboBox;
groupBoxLayout->addWidget(comboBox);
list.append(comboBox);
removeConditionButton->setEnabled(true);
}
void MainDialog::removeCondition()
{
list.removeLast();
if(list.size() == 0)
removeConditionButton->setEnabled(false);
}
To copy to clipboard, switch view to plain text mode
What have I to add to removeCondition()? Or is there a better solution?
Thanks
Bookmarks