Results 1 to 6 of 6

Thread: Dynamically add QPushButtons to dynamically added QGroupBoxes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Dynamically add QPushButtons to dynamically added QGroupBoxes

    How do I dynamically add QPushButtons to dynamically added QGroupBoxes? Here is my code (inside a childwindow) which dynamically adds Groupboxes along with their PushButtons. Onclick of one of these PushButtons there must be added PushButtons inside the belonging GroupBox. But how to place them inside the GroupBox?


    Qt Code:
    1. void MyWidget::systemButton(QGroupBox *groupBox[])
    2. {
    3. systemcounter += 1;
    4.  
    5. QPushButton *btnGtr = new QPushButton();
    6. btnGtr->setText(QString("Guitar: %1").arg(systemcounter));
    7. QVBoxLayout *vbox = new QVBoxLayout;
    8. vbox->addWidget(btnGtr);
    9. groupBox->setLayout(vbox);
    10.  
    11. mainLayout->addWidget(groupBox);
    12.  
    13. QObject::connect(btnGtr, SIGNAL (clicked()), this, SLOT (handleButton()));
    14. }
    15.  
    16. void MyWidget::on_addbutton_clicked()
    17. {
    18. pagecounter += 1;
    19. QGroupBox *groupBox = new QGroupBox(tr("&Page 1"));
    20. QPushButton *btnTest = new QPushButton();
    21. btnTest->setText(QString("Test: %1").arg(pagecounter));
    22.  
    23. top->addWidget(groupBox);
    24. top->addWidget(btnTest);
    25.  
    26. top->maximumSize();
    27.  
    28. mainLayout->addLayout(top);
    29.  
    30. QObject::connect(btnTest, SIGNAL (clicked()), this, SLOT (systemButton()));
    31. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamically add QPushButtons to dynamically added QGroupBoxes

    I am not exactly sure what you are asking for, can you explain with pointing into your code?

    Do you mean that when "btnTest" is clicked, another button should be added to the same button group?

    Cheers,
    _

Similar Threads

  1. Get name of QAction from Menu when dynamically added
    By yapatel in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2014, 08:16
  2. Replies: 2
    Last Post: 3rd June 2013, 16:45
  3. Replies: 2
    Last Post: 30th January 2013, 15:20
  4. Replies: 6
    Last Post: 7th February 2012, 02:03
  5. Connecting dynamically added properties
    By stefkeB in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2008, 15:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.