How to increase the size of the dialog box at run time?



  • I'm calling a dialog at runtime, and adding content to that dialog(radio buttons),
    but size of the dialog fixed and does not display properly (looks very very small) when number of content increases....
    How can i get rid of this?
    The code i wrote as shown below...

    @ void Dialog::Display_header(QStringList headerList)
    {
    for(int i=0;i<headerList.count();i++)
    {
    QRadioButton *Rbutton= new QRadioButton();
    Rbutton->setText(headerList.at(i));
    ui->verticalLayout->addWidget(Rbutton);

    }
    }@


  • Are you sure there is not a fixed size of the dialog? The layout is correctly set for the dialog?



  • How about you ask the layout of your form for the QLayout::sizeHint(), and then just set that size for the dialog using QWidget::setGeometry() ?



  • ya...i set it in designer....
    [quote author="fluca1978" date="1323853587"]Are you sure there is not a fixed size of the dialog? The layout is correctly set for the dialog? [/quote]



  • Have you made sure to set the QDialog's main layout? The easiest way in Qt Designer is to make sure you have deselected everything, and then choose "Lay out horizontally" or one of the other layout-creation options.



  • The following code works for me:

    @void MainWindow::createButtons()
    {

    QWidget* widget = new QWidget( this );
    setCentralWidget( widget );
    verticalLayout = new QVBoxLayout( this );
    widget->setLayout(verticalLayout);
    
    for( int i = 0; i < 10; i++ ){
    
        QString s = "Button # %1";
        s = s.arg( i );
    
        qDebug()<< "Adding button " << i << " " << s;
    
        verticalLayout->addWidget( new QPushButton( s, widget ) );
    }
    

    }
    @

    I guess the problem could be related to the main/central widget layout, as pointed out by Chris.



  • Oops, sorry for the terminology goof, "central" was the word I was looking for, not "main": I had this same problem last week and it turned out that's what I was messing up. If you don't set the central widget for your dialog then when you resize the window nothing happens to the widgets inside it, since they don't know they are supposed to be connected.



  • This is the code i wrote.....here contents adding properly....but dialog size not incrementing accordingly...please tell me what i'm missing here....

    @void Dialog::Display_header(QStringList headerList)
    {

    for(int i=0;i&lt;headerList.count();i++)
    {
        QRadioButton *Rbutton= new QRadioButton();
    
        Rbutton-&gt;setText(headerList.at(i));
        ui->verticalLayout->addWidget(Rbutton);
       ui->verticalLayout->setAlignment(Qt::AlignTop);
    
       ui->verticalLayout->setSpacing(1);
       ui->verticalLayout->setStretch(1,1);
    }
    

    }
    @


Log in to reply
 

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