Delete a layer in run time
-
Hi, i have this code:
@
QWidget *oneLineWidget = new QWidget(this);QHBoxLayout *oneLineWidgetLayout = new QHBoxLayout(); { //added these brackets just for the ease of reading. QLabel *labFirst = new QLabel(tr("ارسال پیام خطا "), oneLineWidget); QPushButton *Btn_Errormsg = new QPushButton(tr("ویرایش"), oneLineWidget); QLabel *labSecond = new QLabel(tr("در صورت دریافت سیگنال از پایانه "), oneLineWidget); QLineEdit *LineEdit = new QLineEdit("", oneLineWidget); QLabel *labSecond1 = new QLabel(tr("و سطح ولتاژ "), oneLineWidget); QPushButton *Btn_Voltaj = new QPushButton(tr("ویرایش "), oneLineWidget); QPushButton *Btn_Delete = new QPushButton(tr("delete"), oneLineWidget); signalMapper->setMapping(Btn_Delete, oneLineWidget); Voltaj->setMapping(Btn_Voltaj, oneLineWidget); connect(Btn_Delete, SIGNAL(clicked()), signalMapper, SLOT(map())); connect(signalMapper, SIGNAL(mapped(QWidget*)),this,SLOT(AddAnalog(QWidget*))); connect(Btn_Voltaj, SIGNAL(clicked()), signalMapper, SLOT(map())); connect(Voltaj, SIGNAL(mapped(QObject*)),this,SLOT(Btn_Voltaj_Click(QWidget*))); oneLineWidgetLayout->addWidget(Btn_Delete); oneLineWidgetLayout->addWidget(Btn_Voltaj); oneLineWidgetLayout->addWidget(labSecond1); oneLineWidgetLayout->addWidget(LineEdit); oneLineWidgetLayout->addWidget(labSecond); oneLineWidgetLayout->addWidget(Btn_Errormsg); oneLineWidgetLayout->addWidget(labFirst); } oneLineWidget->setLayout(oneLineWidgetLayout); ui->verticalLayout_6->addWidget(oneLineWidget); ui->widget->setLayout(ui->verticalLayout_6); ui->scrollArea->setWidget(ui->widget);
@
this code is in a button click slot i.e when i click on a button this code has been executed. and a line of widget(button, labels, line edit) are added to page.http://up.shamsipour-ac.ir/uploads/images/1392/ordibehesht/1366965587891.jpg
i want when i click on delete button that line which clicked on that deleted. i can't wrote this code in delete button click slot because the lines are dynamically added and i can't detect button is from which line. how can i do that?
any idea? -
Hi,
Since you are using a signalMapper and that you are mapping your oneLineWidget with the deleteBtn, why don't you use one of the "mapping" functions from QSignalMapper to retrieve the widget ?
-
you "already asked that question":http://qt-project.org/forums/viewthread/26965/ previously and marked it as solved!
Why do you reopen another thread? -
yes your right. but problem is that when i add three layer(i.e three time this code is executed) when i click on delete button @AddAnalog(QWidget*)@ is executed three time instead of one time.if layer is more this function is execute same time and this is a problem i want to know the problem.