#include "mydialog.h"
MyDialog::MyDialog()
{
_value = 2;
setLayout(_layout);
createDisplay();
}
MyDialog::~MyDialog(){}
// remove all the widgets of layout
void MyDialog
::clearLayout(QLayout* layout
) {
if(!layout) return;
{
if (QWidget* widget
= item
->widget
()){ widget->deleteLater();
}
if (QLayout* childLayout
= item
->layout
()) clearLayout(childLayout);
delete item;
}
}
void MyDialog::createDisplay()
{
clearLayout(layout());
_comboBoxType->addItem("2", 2);
_comboBoxType->addItem("10", 10);
if(_value == 2)
{
_comboBoxType->setCurrentIndex(0);
}else
{
_comboBoxType->setCurrentIndex(1);
}
_layout->addWidget(_comboBoxType, 0, 0);
connect(_comboBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(setValue()));
for(int i=0; i<_value; ++i)
{
_layout->addWidget(w, i+1, 0);
}
adjustSize();
}
void MyDialog::setValue()
{
_value = _comboBoxType->currentData().toInt();
createDisplay();
}
#include "mydialog.h"
MyDialog::MyDialog()
:QDialog()
{
_value = 2;
_layout = new QGridLayout;
setLayout(_layout);
createDisplay();
}
MyDialog::~MyDialog(){}
// remove all the widgets of layout
void MyDialog::clearLayout(QLayout* layout)
{
if(!layout) return;
while (QLayoutItem* item = layout->takeAt(0))
{
if (QWidget* widget = item->widget()){
widget->deleteLater();
}
if (QLayout* childLayout = item->layout())
clearLayout(childLayout);
delete item;
}
}
void MyDialog::createDisplay()
{
clearLayout(layout());
_comboBoxType = new QComboBox();
_comboBoxType->addItem("2", 2);
_comboBoxType->addItem("10", 10);
if(_value == 2)
{
_comboBoxType->setCurrentIndex(0);
}else
{
_comboBoxType->setCurrentIndex(1);
}
_layout->addWidget(_comboBoxType, 0, 0);
connect(_comboBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(setValue()));
for(int i=0; i<_value; ++i)
{
QCheckBox *w = new QCheckBox("Value :", this);
_layout->addWidget(w, i+1, 0);
}
adjustSize();
}
void MyDialog::setValue()
{
_value = _comboBoxType->currentData().toInt();
createDisplay();
}
To copy to clipboard, switch view to plain text mode
Bookmarks