Results 1 to 3 of 3

Thread: Expanding widgets and windows automatically?

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

    Default Expanding widgets and windows automatically?

    Greetings!

    I just purchased "Foundations of Qt Development" (Johan Thelin, 2007), and I read until about chapter 4. I'm trying to practice some of this, so I dove in and I'm creating a simple whack-a-mole type game. So far, it's playable (and configurable if you don't mind changing the setDefaults() function ), but the layout just sucks.

    I have two problems. The scorebox on the side is a QGroupBox with a QGridLayout in it, containing for QLabels that explain your score. The labels expand nicely to fill the grid layout, but the grid layout does not expand to fill the groupbox. I have tried every conceivable size policy from the designer's property editor, and nothing seems to work. Does anyone know how to fix this?

    Second, because I don't know until runtime how many rows and columns there will be in the grid of moles that you click on, I created the function createMoles(), which fills a QGridLayout with moles. A mole is a button-like widget which is 32x32 pixels in size. A grid of 8x8 of these fits nicely in the main window that I have already created with the designer, but if I increase the size of the grid very much, it just goes off the edge of the main window, and you have to manually resize the main window to see them all. Googling has revealed nothing about this problem, and when I tried changing the central widget class in my .ui file with a text editor, everything went to pot. Does anyone know a way to get the main window to automatically expand so that you can see all widgets?

    I hope these aren't too complicated, but I guess it's all part of the learning process.

    I uploaded a tarball of my current source code and ui file to http://www.theanythingbox.com/whack.tar.gz. The forum's attachment mechanism didn't let me upload the file as an attachment, sorry.

    Thanks for any help you can provide!

    - Jakykong

  2. #2
    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: Expanding widgets and windows automatically?

    Open context menu over the background of the group box and choose a layout. Open context menu over the background of the main window and choose a layout. Those red bordered layouts are so called "floating layouts". See also Qt Designer manual: Setting A Top Level Layout.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    jakykong (25th September 2008)

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

    Default Re: Expanding widgets and windows automatically?

    That did the trick. Thanks!

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.