jeudi 3 juin 2021

i wanna to set actionlistener to the button which i have created dynamically in qt widget

i have created a button"publish button" which create a new widget with some buttons on it each time i clicked on this button now i wanna to put action listener to the dynamic button which created in each new wedget this code of how my publish button work on click it :

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
          QObject::connect(
          ui->publishbuttontimeline_2, &QPushButton::clicked,
          this, &MainWindow::onAddWidget);
}

this is my constructor which connect the publish button with the method which create new widget and its buttons

this is the code of the method onAddWidget :

void MainWindow::onAddWidget()
{
    //define BoxLayout and each post block
    QVBoxLayout*Layout=qobject_cast<QVBoxLayout*>(ui->scrollareapoststimeline->layout());
    QWidget*postblock=new QWidget();
    QBoxLayout*boxlayout=new QBoxLayout(QBoxLayout::TopToBottom,postblock);

    QPushButton *commentbutton=new QPushButton("comment");

     boxlayout->insertWidget(0,commentbutton);
;
     postblock->setLayout(boxlayout);

    //push the boxlayout which have the post components to the QVBox of the scrollview
    Layout->insertWidget(0,postblock);
}

now i wanna but an action to the "comment button" to open new widget when click on it how can i do that with qt

Aucun commentaire:

Enregistrer un commentaire