Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Setting the geometry of a form after setting the layout



  • Hi all,

    I have a form in which I create the radiobuttons at runtime.
    What I do is:

    @ lay->setVerticalSpacing(1);
    lay->setHorizontalSpacing(1);
    lay->setSizeConstraint(QLayout::SetMaximumSize);

    setLayout(lay);
    
    ...
    
    foreach(QString str_cap, cap)
    {
        QRadioButton *button1 = new QRadioButton();
        button1->setText(QString("%1").arg(str_cap));
        lay->addWidget(button1, localcount, int(localcount/10));
        group->addButton(button1, count);
        count++;
        localcount++;
    }
    

    @

    This works perfect to show the first set of radiobuttons. Whenever user clicks on a radiobutton, I make existing radiobuttons hidden using the following code:

    @ foreach(QAbstractButton *but, group->buttons())
    but->hide();
    @

    This code works also good, I see the the all existing radiobuttons become hidden. However, I use the same function to recreate a second bunch of radiobuttons. What happens is that, my code hides the first group and shows the new bunch but the form size comes as zero. So, after clicking on a radiobutton in the first group, the second group is shown but I can only see it after resizing the form window with mouse. So, how can I adjust the size of the layout after adding-removing some radiobuttons?


  • Lifetime Qt Champion

    Hi,

    You shouldn't need to but you can try to call adjustSize

    Hope it helps


Log in to reply