SOLVED : Display QgroupBox



  • Here a very stupid question. I want to display a dialog box (when an action is selected) allowing to select options using checkboxes. For that I used a groupbox, but I am not able to display it. When the program is open I can clicked on the "select conformers" button that is leading to this function:

    @
    void MainWindow::on_actionSelect_Conformers_triggered()
    {
    QGroupBox *groupBox = new QGroupBox(this);
    groupBox->setFlat(true);

    QCheckBox *checkBox1 = new QCheckBox(tr("&Checkbox 1"));
    QCheckBox *checkBox2 = new QCheckBox(tr("C&heckbox 2"));
    checkBox2->setChecked(true);
    QCheckBox *tristateBox = new QCheckBox(tr("Tri-&state button"));
    tristateBox->setTristate(true);
    tristateBox->setCheckState(Qt::PartiallyChecked);
    
    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->addWidget(checkBox1);
    vbox->addWidget(checkBox2);
    vbox->addWidget(tristateBox);
    vbox->addStretch(1);
    groupBox->setLayout(vbox);
    groupBox->show();
    

    }
    @

    I am sur I am going through this code but nothing is happening or displaying. What should I do to have this groupbox showing on my MainWindow (like a Qmessage box)?

    Thanks for your answers.



  • Welcome to forum.

    Don't pass the parent to GroupBox. Try doing like this.

    @QGroupBox *groupBox = new QGroupBox();@


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    On a side not, why not create your own dialog for that widget ? It will simplify your code



  • Hi,

    You also can create a new QDialog class with an ui, then add a QLabel and show there a message, you can create an delete it, so you can pass the message in the constructor, something like that
    @
    MyDialog* mDialog;

    MainClass::MainClass(){
    mDialog = new MyDialog("MyMessage",this);
    ....
    ....
    }
    void MainClass::onCloseEvent(){//slot connected to some signal of the dialog
    mDialog->close();
    delete mDialog;
    }
    @

    or you can create once, and make an method that set a new message
    @mDialog->setMyMessage("My New Message");@

    if you don't want that your main window inherits the Dialog, just ignore this word.
    @mDialog = new MyDialog("MyMessage");@



  • Hi,

    thank you so much for your replies.

    @Deerhendra: It works! It is kind of upsetting that I don't understand why but it works.

    @SGaist and bladice. Create a new dialog box was my first try but I couldn't make it work. But let's try again....



  • It is because you are setting the another widget as parent by passing this. So groupbox is child MainWindow. It needs to be shown along with parent. Child ownership is transferred to parent.



  • I see.
    Thanks



  • Can you put this request to SOLVED state by editing the question itself ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.