PDA

View Full Version : How to resize window with pushbutton



kaydknight
13th January 2007, 11:58
Hi, I'm a total newbie with Qt. Have been looking the QT assistant help for a while to figure out how to resize the window by pressing just a pushbutton

Below is my code snippet:



QApplication app(argc,argv);
QPushButton quit("Quit");
...
...
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(resize(500,500));


When I press the pushbutton, the app is still not resized. I'm just trying to get a hang on qt, and that's why I just really want to know how to do this.

I read the assistant which said that if i call for resize, then a resize event will automatically occur, but somehow the app is not resizing at all. Hope anyone can help on this. Thanks in advance!

jacek
13th January 2007, 12:15
First of all QApplication isn't a widget, so you can't resize it. Secondly QWidget::resize() isn't a slot, but a normal method, so you can't connect any signals to it. Also you can't put parameter values inside SLOT() and SIGNAL() macros.

You need a custom slot to do this:
QObject::connect(&quit, SIGNAL(clicked()), &someWidget, SLOT(resize());
...
void SomeWidget::resize()
{
resize( 500, 500 );
}

jpn
13th January 2007, 12:17
You cannot put parameter values into the connect statement. You are only allowed to put possible parameter types, and in this case the parameter types must match. For further details, see Signals and Slots (http://doc.trolltech.com/4.2/signalsandslots.html).

What you need is most likely a custom slot. Connect the button's clicked() signal to that slot and do the resizing there. Again, for details, see the link above.

Only widgets are resizable. See QWidget::resize(). You cannot resize QApplication as it's nothing visible.