PDA

View Full Version : how to increase the size of the dialog box at run time?



aurora
14th December 2011, 07:32
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);

}
}

ChrisW67
14th December 2011, 08:56
Extension Example

aurora
14th December 2011, 09:15
Extension Example
Thank u chris.....but in my case the dialog may contain only one radio button or it can increase upto 30......depending on that the size of dialog must increase.....i tried vertical spacer, but that didnt help me...:(
As number of radio button increases the font becomes small and dialog size also wont expand...

ChrisW67
14th December 2011, 09:30
The key is the
mainLayout->setSizeConstraint(QLayout::SetFixedSize); line

aurora
22nd December 2011, 07:16
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<headerList.count();i++)
{
QRadioButton *Rbutton= new QRadioButton();

Rbutton->setText(headerList.at(i));
ui->verticalLayout->addWidget(Rbutton);
ui->verticalLayout->setAlignment(Qt::AlignTop);

ui->verticalLayout->setSpacing(1);
ui->verticalLayout->setStretch(1,1);
}
}

ChrisW67
22nd December 2011, 08:23
:confused: See my previous post and the Extension Example. Seriously.

Here is a potted example:


#include <QtGui>

class MagicDialog: public QDialog {
Q_OBJECT
public:
MagicDialog(QWidget *p = 0): QDialog(p) {
QVBoxLayout *layout = new QVBoxLayout;
layout->setSizeConstraint(QLayout::SetFixedSize); // <<<<< THIS
setLayout(layout);

QPushButton *button = new QPushButton("Add one", this);
connect(button, SIGNAL(clicked()), SLOT(addOne()));
layout->addWidget(button);

button = new QPushButton("Remove one", this);
connect(button, SIGNAL(clicked()), SLOT(removeOne()));
layout->addWidget(button);
}
public slots:
void addOne() {
QRadioButton *rbutton = new QRadioButton(QString("Label %1").arg(rbuttons.size()), this);
rbuttons.append(rbutton);
layout()->addWidget(rbutton);
}
void removeOne() {
if (rbuttons.size()) {
QRadioButton *rbutton = rbuttons.takeLast();
rbutton->deleteLater();
}
}
private:
QList<QRadioButton*> rbuttons;
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MagicDialog d;
d.show();
return app.exec();
}
#include "main.moc"