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. How to dynamically add QPushButton in QStackedWidget?
Forum Updated to NodeBB v4.3 + New Features

How to dynamically add QPushButton in QStackedWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 518 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sys1
    wrote on last edited by sys1
    #1

    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->setText(QString::fromLocal8Bit("next"));
    nextButton->setGeometry(QRect(QPoint(1150, 620), QSize(93, 28)));
    connect(nextButton, SIGNAL(clicked()), this, SLOT(readCustomerGraph()));
    ui.StackedWidget->addWidget(nextButton);
    nextButton->show();

    =====================================================

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

    I hope for help.
    thank you.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.
      https://wiki.qt.io/New_Signal_Slot_Syntax

      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
      ui->page
      or ui->page_2
      etc
      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.

      1 Reply Last reply
      1

      • Login

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