#include <QtGui>
class MagicDialog
: public QDialog { Q_OBJECT
public:
layout
->setSizeConstraint
(QLayout::SetFixedSize);
// <<<<< THIS setLayout(layout);
connect(button, SIGNAL(clicked()), SLOT(addOne()));
layout->addWidget(button);
connect(button, SIGNAL(clicked()), SLOT(removeOne()));
layout->addWidget(button);
}
public slots:
void addOne() {
rbuttons.append(rbutton);
layout()->addWidget(rbutton);
}
void removeOne() {
if (rbuttons.size()) {
rbutton->deleteLater();
}
}
private:
QList<QRadioButton*> rbuttons;
};
int main(int argc, char *argv[])
{
MagicDialog d;
d.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
class MagicDialog: public QDialog {
Q_OBJECT
public:
MagicDialog(QWidget *p = 0): QDialog(p) {
QVBoxLayout *layout = new QVBoxLayout;
layout->setSizeConstraint(QLayout::SetFixedSize); // <<<<< THIS
setLayout(layout);
QPushButton *button = new QPushButton("Add one", this);
connect(button, SIGNAL(clicked()), SLOT(addOne()));
layout->addWidget(button);
button = new QPushButton("Remove one", this);
connect(button, SIGNAL(clicked()), SLOT(removeOne()));
layout->addWidget(button);
}
public slots:
void addOne() {
QRadioButton *rbutton = new QRadioButton(QString("Label %1").arg(rbuttons.size()), this);
rbuttons.append(rbutton);
layout()->addWidget(rbutton);
}
void removeOne() {
if (rbuttons.size()) {
QRadioButton *rbutton = rbuttons.takeLast();
rbutton->deleteLater();
}
}
private:
QList<QRadioButton*> rbuttons;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MagicDialog d;
d.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks