Results 1 to 7 of 7

Thread: How to expand QDockWidget as main window grows

  1. #1
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to expand QDockWidget as main window grows

    I'm using Qt 4.4.3 and Designer. I am trying to get a QDockWidget to resize automatically both horizontally and vertically (it does resize automatically vertically) as the user changes the main window size by dragging, as opposed to the user having to enlarge the dock widget via the splitter. A simplified example of the layout is attached.

    I tried implementing resizeEvent() for the main window and resizing the dock widget to account for horizontal growth when it is called, but the dock widget's width seems to be "stuck". (I also tried this with setSizeConstraint(QLayout::SetNoConstraint).)

    Are there other properties that need to be changed, or is another approach (e.g. a custom layout) necessary?

    Thanks in advance,
    Martin
    Attached Images Attached Images

  2. #2
    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: How to expand QDockWidget as main window grows

    You can check for maximum width set for dock widget, or minmnum for ur central widget.

  3. #3
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to expand QDockWidget as main window grows

    Quote Originally Posted by aamer4yu View Post
    You can check for maximum width set for dock widget, or minmnum for ur central widget.
    I set the horizontal size policy for the dock widget to Maximum in Designer, and set the horizontal size policy for ui.centralWidget to QSizePolicy::Minimum in the code, but it didn't change anything.

    The resizeEvent() code does increase the width of the dock widget, but it snaps back to its original width after each increase in width.

    Is there something else that is required?

    Thanks,
    Martin

  4. #4
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to expand QDockWidget as main window grows

    I wanted to add that changing the size of the docked QDockWidget programmatically using resize works fine, until the main window is dragged. When that happens, the QDockWidget returns to its original horizontal size.

    What am I missing?

  5. #5
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: How to expand QDockWidget as main window grows

    I think I figured it out:

    • Added an outer QWidget to the main window

    • Put the QDockWidget inside the outer QWidget

    • Used a grid layout in the outer widget, with size policy preferred/preferred

    • Put "controls" in an area to the right of the dock widget inside a QFrame; this has a size policy fixed/minimum expanding so that the controls don't change in size

    • To keep the controls from expanding vertically, added a "dummy" frame at the bottom of the QFrame, set to expanding/expanding

    • Top level layout is grid, preferred/preferred


    Also, so that when the QDockWidget is undocked, the main window contracts to just the size of the controls area, connected a slot to the "topLevelChanged" signal, in which the top level layout is resized() to its original size - dockWidget->frameSize().

    I think this is going to work, but the true test is integrating this back into the application I'm developing, that puts an Open Inventor SoQtRenderArea into the QDockWidget.

  6. #6
    Join Date
    Sep 2008
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to expand QDockWidget as main window grows

    Did you ever get this to work the way that you wanted. I am trying to set something like this up right now.

    I am not sure exactly what you mean by "Added an outer QWidget". Is it possible for you to add a few lines of source code showing how you accomplished this?

    Thanks in advance,
    amicitas

  7. #7
    Join Date
    Mar 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: How to expand QDockWidget as main window grows

    I guess it is not possible on that way with current Qt. Any other ideas?

Similar Threads

  1. access main window from function
    By eric in forum Qt Programming
    Replies: 6
    Last Post: 19th January 2008, 22:29
  2. minimizing main window
    By eric in forum Qt Programming
    Replies: 4
    Last Post: 28th November 2007, 17:54
  3. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 16:40
  4. Replies: 5
    Last Post: 5th August 2006, 00:44
  5. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 11:21

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.