Results 1 to 10 of 10

Thread: How can size of QMainWindow's central widget be managed?

  1. #1
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question How can size of QMainWindow's central widget be managed?

    Hi,
    I have a main window with a central widget which can grow horizontally when needed but should not grow vertically (just like horizontal slider) along-with 4 dock widgets. Problem is that when the main window's size is increased, central widget's vertical size is also increased, which should not be happening. I have tried
    Qt Code:
    1. setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    To copy to clipboard, switch view to plain text mode 
    with no success.
    Can you please show me the way?
    Regards,

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How can size of QMainWindow's central widget be managed?

    Try setting a maximum height to the widget.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can size of QMainWindow's central widget be managed?

    Quote Originally Posted by high_flyer View Post
    Try setting a maximum height to the widget.
    I tried with
    Qt Code:
    1. setFixedHeight(sizeHint().height());
    To copy to clipboard, switch view to plain text mode 
    Now the widget's vertical size remains constant but the area which is supposed to be occupied by central widget is still not restricted resulting in empty area below the widget.

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

    Default Re: How can size of QMainWindow's central widget be managed?

    Why should it be restricted? You said you didn't want the central widget size to change and it doesn't change. You don't want the main window size to change as well? If so, then either set its maximum height or set a layout constraint on it.
    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.


  5. #5
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can size of QMainWindow's central widget be managed?

    Quote Originally Posted by wysota View Post
    Why should it be restricted? You said you didn't want the central widget size to change and it doesn't change. You don't want the main window size to change as well? If so, then either set its maximum height or set a layout constraint on it.
    Yes, now height of central widget does not change but what's the point of having empty space below it when that space can be effectively used by other dock widgets?

    Please look at the following screen-shots for a better idea.
    Optimum size:


    After increasing window's size:

  6. #6
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Re: How can size of QMainWindow's central widget be managed?

    I don't know if it is the best way to do it, but I would use a QWidget with two QWidgets on it. Set the central widget to the parent, and give the parent a horizontal layout. Put the things you want to stay constant on the top widget and give that widget a fixed size. The bottom widget, with your list of songs will expand then as necessary.

  7. #7
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can size of QMainWindow's central widget be managed?

    Quote Originally Posted by JPNaude View Post
    I don't know if it is the best way to do it, but I would use a QWidget with two QWidgets on it. Set the central widget to the parent, and give the parent a horizontal layout. Put the things you want to stay constant on the top widget and give that widget a fixed size. The bottom widget, with your list of songs will expand then as necessary.
    This is good only for simple case not when you have a number of dock widgets giving you the complete control over the placement of each dock.


  8. #8
    Join Date
    Aug 2011
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can size of QMainWindow's central widget be managed?

    Hi, I'm facing the exact same problem. Have you already found a solution for it? If so, would you please share it?

    Thanx in advance
    Jonny

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How can size of QMainWindow's central widget be managed?

    What problem? This thread discusses correct operation of the Qt layout system

  10. #10
    Join Date
    Dec 2011
    Posts
    60
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Having the same issue with resizing

    I'm facing the same issue and I haven't found anyone who appears to have solved it, at least in a way that Google can find.

    Like the OP, I have a central widget and a number of dockwidgets. In my case the dockwidgets are to the right of the central widget.

    When the main window is resized, I want the dock widgets to grow to fill the horizontal space and the central widget to remain fixed. Yet, of course, the exact opposite happens.

    And the central widget is immune to any attempts at setting a size policy.

    The behavior I describe seems like it should be the standard behavior, yet it's apparently very difficult to achieve.

    Is there any simple way to have dockwidgets expand to fill the space while the central widget remains fixed?

    qt_resize_bug.png
    Last edited by alketi; 28th March 2014 at 21:47.

Similar Threads

  1. How to set proportion between dockwidget and central widget
    By christina123y in forum Qt Programming
    Replies: 6
    Last Post: 14th July 2009, 17:48
  2. Replies: 2
    Last Post: 23rd March 2009, 17:26
  3. QDockWidgets without central widget
    By JoeMerchant in forum Qt Programming
    Replies: 17
    Last Post: 8th August 2007, 14:52
  4. paint central widget of a QMainWindow???
    By Shuchi Agrawal in forum Newbie
    Replies: 3
    Last Post: 17th January 2007, 08:02
  5. Central Widget of QMainWindow
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2006, 18:32

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.