Results 1 to 6 of 6

Thread: Maximize a widget (to fill its parent

  1. #1
    Join Date
    Oct 2008
    Posts
    2

    Default Maximize a widget (to fill its parent

    hi,

    I have a QglWidget which I would like to be 100% of the size of his parent QMainWindow.

    When I create the QglWidget he is the right size (parent auto-created), but now I tried to maximize it with :

    Qt Code:
    1. QSizePolicy sizePolicy;
    2. sizePolicy.setHorizontalPolicy(QSizePolicy::Expanding);
    3. sizePolicy.setVerticalPolicy(QSizePolicy::Expanding);
    4. qglWidget.setSizePolicy(sizePolicy);
    To copy to clipboard, switch view to plain text mode 

    but it doesn't seem to work

    Any idea ?

  2. #2

    Default Re: Maximize a widget (to fill its parent

    What if you stick it in a layout and then add a stretch factor greater than 1?

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Maximize a widget (to fill its parent

    Hi,

    1. Set layout for the window and add the widget to the layout with enabled max stretch.
    2. When maximizing the main window set widget geometry to fill the whole window.(brutal force)
    3. Make sure you do not have any "bar" objects (toolbar,etc) which will not allow the widget to make the whole available space.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Maximize a widget (to fill its parent

    Try setting the margins ans spacing in layout to zero.
    Else if you want to show some widget maximised, you can use QWidget::showMaximized()

  5. #5
    Join Date
    Jan 2006
    Posts
    371
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Maximize a widget (to fill its parent

    Similar question to this one:

    I saw in a few web pages, a flash movie that contains a button that when you press it, the movie goes out of the original frame, and fits the whole window (not full screen!)

    I would like to implement this in a QWidget:
    I want to yank a QWidget from a layout, and then force it to be take the whole content of the window. Has anyone done such thing and can give me some hints about how can I do this?

  6. #6
    Join Date
    Oct 2008
    Posts
    2

    Default Re: Maximize a widget (to fill its parent

    hello guys,

    it was a layout problem indeed, but I resolved it just by using setCentralWidget instead of addWidget

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Replies: 6
    Last Post: 3rd September 2008, 14:27
  3. Replies: 1
    Last Post: 17th July 2008, 14:42
  4. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00
  5. Referencing Parent Widget from Child
    By taylor34 in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2006, 15:13

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
  •  
Qt is a trademark of The Qt Company.