Results 1 to 14 of 14

Thread: resizing widgets when user resizes mainwindow

  1. #1
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default resizing widgets when user resizes mainwindow

    Hello all,

    I'd like when the user resizes the main window of my app, the widgets inside the main window to be resized automatically too.

    Ive set the sizePolicy of my main window to preferred.
    all the widgets inside the main window are placed inside a tab widget which is under the centralWidget.

    this is what ive tried so far:

    Qt Code:
    1. /* i suppose that when the user resizes the window, the height changes so i tried to check it with the following : */
    2. if(!minimumSize().height == 800) //where 800 is the default height for the window
    3. {
    4. tabwidget->updateGeometry();
    5. // centralWidget->updateGeometry();
    6. // setupUi(this);
    7. }
    To copy to clipboard, switch view to plain text mode 

    i hope you get the meaning,
    any help is appreciated

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: resizing widgets when user resizes mainwindow

    Use layouts, then you don't have to do the children resizing by your own: QLayout, QGridLayout...

  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    620
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: resizing widgets when user resizes mainwindow

    Quote Originally Posted by Lykurg View Post
    Use layouts, then you don't have to do the children resizing by your own: QLayout, QGridLayout...
    Lykurg I'm trying to do the same but seems impossible for me to get good results. I'm becoming crazy.
    Can you help me please?
    I can send you some code

    Best
    Franco Amato

  4. #4
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resizing widgets when user resizes mainwindow

    EDITED

    ive tried to lay my widget under a grid layout, for some strage reason the app compiled and run ok but i lost connection with my .cpp file, for ex i clicked on a button on my app and nothing happened! lol, when i removed the grid layout everything worked correctly again :P..

    ive also tried to right click to my tabwidget and lay out as grid layout, but then i couldnt setup the widgets where i want them to be in the form.. lol...

    so lets forget the layout method, i dont have a problem to code all of my widgets in the app to resize automatically as long as i know how to do it...

    so please help hehe xD
    Last edited by Mystical Groovy; 19th December 2009 at 13:17.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: resizing widgets when user resizes mainwindow

    Using QLayout correct don't break any functionality! Let me see some code and I might tell you the error... Just post it here.

  6. #6
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resizing widgets when user resizes mainwindow

    hi and thx for the reply
    well basically im doing all the form work using the QtCreator's intergrated designer, so i dont have a spesific laying out widgets code on my source file.

    I could try to lay my widget in a QLayout using code if this is necessary (im trying to avoid setting up the widgets again via code coz it'll take ages you see )

  7. #7
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resizing widgets when user resizes mainwindow

    oh!, i have some button that to be shown, they'll have to be triggered first not done with the designer and layeded out on a QVBoxLayout and QHBoxLayout, maybe thats why it breaks the functionality?

    Qt Code:
    1. vbox = new QVBoxLayout;
    2. vbox->addWidget(pkgdesclbl);
    3. vbox->addWidget(pkgdescText);
    4. vbox->addWidget(pkgfilelistlbl);
    5. vbox->addWidget(pkgfilelistText);
    6. vbox->addWidget(consoleOutlbl);
    7. vbox->addWidget(consoleOutText);
    8.  
    9. hbox = new QHBoxLayout(vbox);
    10. hbox->addWidget(pkgsaveBtn);
    11. hbox->addWidget(pkgcopyBtn);
    12.  
    13. pkginfoBox->setLayout(vbox); //this is a QFrame in my applications form
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resizing widgets when user resizes mainwindow

    well i managed to lay out the tabwidget in my main window and when i resize the main window the tabwidget resizes along but not the widgets under the tabwidget.

    i tried to lay out the widgets inside the tabwidget but as before it messes up my widget potitions and i cant set them in the way i want...

  9. #9
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resizing widgets when user resizes mainwindow

    any help please?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: resizing widgets when user resizes mainwindow

    Quote Originally Posted by Mystical Groovy View Post
    any help please?
    Sure. As soon as you post the code reproducing the problem or at least a screenshot of what you want to obtain.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resizing widgets when user resizes mainwindow

    ok look, the problem is that i cant get the widgets inside tabwidget in my application resize along with the main window when the user resizes it.

    first i tried to do this (as posted in the first post)
    Qt Code:
    1. /* i suppose that when the user resizes the window, the height changes so i tried to check it with the following : */
    2. if(!minimumSize().height == 800) //where 800 is the default height for the window
    3. {
    4. tabwidget->updateGeometry();
    5. // centralWidget->updateGeometry();
    6. // setupUi(this);
    7. }
    To copy to clipboard, switch view to plain text mode 

    then Lykurg suggested to use layouts, but when i lay the widgets inside my tabwidget in a grid layout it messes the potition of the widgets up and i cant get them to where i want them to be shown.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: resizing widgets when user resizes mainwindow

    That's why I ask you to post a screenshot (or better yet a ui file) and we'll help you place them in a layout. It's either that or doing the layout manually by reimplementing resizeEvent() of each and every tab in your window. It's really much quicker to do it with layouts.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resizing widgets when user resizes mainwindow

    here you go mate, thanks
    Attached Files Attached Files

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: resizing widgets when user resizes mainwindow

    Here you go. But I'd replace all those QToolButton instances with QPushButtons. Their size will adjust to the parent without the need to change the default size policy (I didn't change them on purpose so that you can see the difference).
    Attached Files Attached Files
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. problem while resizing mainwindow.
    By phillip_Qt in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2009, 08:44
  2. Replies: 2
    Last Post: 31st July 2009, 09:18
  3. how do I discard user changes on widgets
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 30th December 2008, 07:50
  4. Child Widgets In MainWindow
    By RY in forum Newbie
    Replies: 3
    Last Post: 4th October 2008, 08:39
  5. scrolled widgets containers in Mainwindow
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2006, 14:40

Tags for this Thread

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.