Important: Please read the Qt Code of Conduct -

How to dynamically add QPushButton in QStackedWidget?

  • QStackedWidget is already complete by QT creator.
    but I want add QPushButton in QStackedWidget as coding(C++).
    What I want to do is add a new button to the bottom of the current screen
    when I press a button that already exists in the QStackedWidget.

    Below are some of the sources.


    QPushButton* nextButton = new QPushButton();
    nextButton->setGeometry(QRect(QPoint(1150, 620), QSize(93, 28)));
    connect(nextButton, SIGNAL(clicked()), this, SLOT(readCustomerGraph()));


    When I do this, the button is visible but cannot be clicked.

    I hope for help.
    thank you.

  • Lifetime Qt Champion

    Hi and welcome to the forums.

    if possible you should use the new connect syntax as that tells if a connection cannot be made at compile time.

    in any case,
    the addwidget you are using is for adding new pages!
    Is that what you want ? Its very odd to use a button as a page.

    if you mean to insert into the existing pages,
    then you can access that widget via
    or ui->page_2
    You can see names in the Designer.

    But often you want such buttons outside of the page and under the stackedwidget as you want them always there.

Log in to reply