Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Delete a layer in run time
Forum Update on Monday, May 27th 2025

Delete a layer in run time

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mehdi.nine
    wrote on 26 Apr 2013, 08:42 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 26 Apr 2013, 08:53 last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 26 Apr 2013, 08:58 last edited by
        #3

        you "already asked that question":http://qt-project.org/forums/viewthread/26965/ previously and marked it as solved!
        Why do you reopen another thread?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mehdi.nine
          wrote on 26 Apr 2013, 12:32 last edited by
          #4

          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.

          1 Reply Last reply
          0

          1/4

          26 Apr 2013, 08:42

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved