Qt World Summit: Register Today!

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);

    QCheckBox *checkBox1 = new QCheckBox(tr("&Checkbox 1"));
    QCheckBox *checkBox2 = new QCheckBox(tr("C&heckbox 2"));
    QCheckBox *tristateBox = new QCheckBox(tr("Tri-&state button"));
    QVBoxLayout *vbox = new QVBoxLayout;


    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.

  • Qt Champions 2017

    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;

    mDialog = new MyDialog("MyMessage",this);
    void MainClass::onCloseEvent(){//slot connected to some signal of the dialog
    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....

  • Qt Champions 2017

    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.

  • Qt Champions 2017

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

Log in to reply