Results 1 to 3 of 3

Thread: How to resize window with pushbutton

  1. #1
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to resize window with pushbutton

    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:

    Qt Code:
    1. QApplication app(argc,argv);
    2. QPushButton quit("Quit");
    3. ...
    4. ...
    5. QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(resize(500,500));
    To copy to clipboard, switch view to plain text mode 

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to resize window with pushbutton

    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:
    Qt Code:
    1. QObject::connect(&quit, SIGNAL(clicked()), &someWidget, SLOT(resize());
    2. ...
    3. void SomeWidget::resize()
    4. {
    5. resize( 500, 500 );
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to resize window with pushbutton

    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.

    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.
    Last edited by jpn; 13th January 2007 at 12:21. Reason: oops, who posted it in the middle of editing..
    J-P Nurmi

Similar Threads

  1. Replies: 3
    Last Post: 23rd July 2006, 18:02
  2. Move window in Clone Mode
    By ultrabrite in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2006, 18:22
  3. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21
  4. Main window
    By Michiel in forum Qt Tools
    Replies: 1
    Last Post: 20th March 2006, 23:54
  5. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.