Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Attach a dynamic button to a window
Qt 6.12 LTS is out! See what's new in the release blog

Attach a dynamic button to a window

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.9k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    So basically I want to make the following: When a button is pushed, create a button at point X with size Y which has text which is extracted from a textEdit. This is the function I have made:

    @void MainWindow::on_pushButton_released()
    {
    QString a = ui->textEdit->toPlainText();
    QPushButton* ptr = new QPushButton(a);
    addWidget(ptr); // I figured I should use this function, thing is I don't know what should call it
    ptr->show();
    ptr->setGeometry(260, 140, 40, 40);
    }@

    It works, however the window appears on the 260, 140 on my desktop. I want it to be 260,140 in the main window, wherever it is. Thanks in advance.

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      try this:
      @ QString a = ui->textEdit->toPlainText();
      QPushButton* ptr = new QPushButton(this);
      ptr->setText(a);
      ptr->show();
      ptr->setGeometry(260, 140, 40, 40);@

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thank you, that worked ! I didn't attach the widget to the window and that is where the problem was.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          You are welcome :)
          Glad to hear it.

          1 Reply Last reply
          0

          • Login

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