MyWidget
::MyWidget(QWidget *parent
) :{
hbox->addWidget(deletebutton);
hbox->addWidget(addbutton);
flowlayout = new FlowLayout(widget);
widget->setLayout(flowlayout);
scrollArea->setWidgetResizable(true);
scrollArea->setWidget(widget);
vbox->addLayout(hbox);
vbox->addWidget(scrollArea);
setLayout(vbox);
connect(deletebutton, SIGNAL(clicked()), this, SLOT(deleteButton()));
connect(addbutton, SIGNAL(clicked()), this, SLOT(addButton()));
}
void MyWidget::deleteButton() {
flowlayout->takeAt(0);
flowlayout->update();
qDebug() <<"deleted: "<<flowlayout->count();
}
void MyWidget::addButton() {
flowlayout->addWidget(newButton);
flowlayout->update();
connect(newButton, SIGNAL(clicked()), this, SLOT(buttonpressed()));
qDebug() <<"added: "<<flowlayout->count();
}
void MyWidget::buttonpressed() {
qDebug() <<"button pressed";
}
MyWidget::MyWidget(QWidget *parent) :
QWidget(parent)
{
deletebutton = new QPushButton("delete",this);
addbutton = new QPushButton("add",this);
hbox = new QHBoxLayout();
hbox->addWidget(deletebutton);
hbox->addWidget(addbutton);
QWidget* widget = new QWidget(this);
flowlayout = new FlowLayout(widget);
widget->setLayout(flowlayout);
QScrollArea *scrollArea = new QScrollArea();
scrollArea->setWidgetResizable(true);
scrollArea->setWidget(widget);
vbox = new QVBoxLayout(this);
vbox->addLayout(hbox);
vbox->addWidget(scrollArea);
setLayout(vbox);
connect(deletebutton, SIGNAL(clicked()), this, SLOT(deleteButton()));
connect(addbutton, SIGNAL(clicked()), this, SLOT(addButton()));
}
void MyWidget::deleteButton() {
flowlayout->takeAt(0);
flowlayout->update();
qDebug() <<"deleted: "<<flowlayout->count();
}
void MyWidget::addButton() {
QPushButton* newButton = new QPushButton("button");
flowlayout->addWidget(newButton);
flowlayout->update();
connect(newButton, SIGNAL(clicked()), this, SLOT(buttonpressed()));
qDebug() <<"added: "<<flowlayout->count();
}
void MyWidget::buttonpressed() {
qDebug() <<"button pressed";
}
To copy to clipboard, switch view to plain text mode
Bookmarks