PDA

View Full Version : Resizing the dialog box dynamically



vvbkumar
14th June 2006, 10:06
hi ,

I am new to QT.., my problem is can we resize the dialog dynamically, :confused:

i.e, using any controls, Say for eg slider, can we resize the dialog when the slider is moved

thanks in advance :)

wysota
14th June 2006, 10:11
Yes, of course. You have to connect the slider's valueChanged signal to a custom slot which will resize() the dialog.

vvbkumar
19th June 2006, 08:48
hi
i have tried using resize(), but its not effecting on the dialog box??? :confused:

can u pl help me out.

thanks in advance,

wysota
19th June 2006, 14:05
Can you show some code you wrote for that?

vvbkumar
20th June 2006, 08:38
here is the code :


int main (int argc, char *argv[]){
QApplication app(argc, argv);
QDialog *dialog = new QDialog();
QHBox *hbox = new QHBox;
hbox->setCaption("Slider is at : ");
hbox->setMargin(6);
hbox->setSpacing(6);
QSpinBox *spinbox = new QSpinBox(hbox);
QSlider *slider = new QSlider(Qt::Horizontal, hbox);
spinbox->setRange(0,100);
slider->setRange(0,100);
QObject::connect(spinbox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)), spinbox, SLOT(setValue(int)));
int x = spinbox->value();
int y = slider->value();
hbox->resize(x,y);
spinbox->setValue(11);
app.setMainWidget(hbox);
hbox->show();
return app.exec();
}

e8johan
20th June 2006, 08:54
This only resizes the dialog to the initial state (i.e. 0 by 0 pixels). You've also interconnected the slider and the spin box. You need to subclass the dialog and create two slots - setX and setY which you then connect to the slider and spinbox.