Just add a layout and put your newborn shortcuts in it.
QHBoxLayout *layout = new QHBoxLayout; // or some another QLayout descendant layout->addWidget(newWidget); widget->setLayout(layout);
The only place I had to change was to add a layout to the Widget, and then
void EditThingsWindow::addButtonClicked() { QLabel * label=new QLabel(this); layout->addWidget(label); label->move(200,160); label->setText(";;;;;;;;;;;;;;"); }
Done.
If you MUST (not do!) A mess with absolute positioning, you must do all of these code templates yourself. Headings and attachments omitted.
int main(int argc, char *argv[]) { QApplication a(argc, argv); EditThingsWindow w(0); w.show(); return a.exec(); } EditThingsWindow::EditThingsWindow(QWidget *parent):QWidget(parent) { i = 0; setGeometry(2, 2, 400, 400); add=new QPushButton(this); add->setGeometry(2, 2, 100, 20); add->setText("Add"); add->move(20,10); QObject::connect(add,SIGNAL(clicked()),this,SLOT(addButtonClicked())); } void EditThingsWindow::addButtonClicked() { QLabel * label=new QLabel(this); label->setGeometry(10, 30 + i* 30, 50, 20); i++; label->setText(";;;;;;;;;;;;;;"); label->show(); }
Maxim Popravko
source share