Results 1 to 20 of 21

Thread: what to do to make windows non-resizable?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question what to do to make windows non-resizable?

    Please find a small project of mine attached. I would like to know what to do to make the window non-resizable. I tried setting the sizePolicy of the main window to Fixed,Fixed (in Designer) but it still is resizable. What am I missing? Thanks in advance.
    Attached Files Attached Files
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what to do to make windows non-resizable?

    In Ui.cpp, at the end of the constructor, put:

    Qt Code:
    1. setFixedSize( sizeHint () );
    To copy to clipboard, switch view to plain text mode 


    Regards.

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

    Default Re: what to do to make windows non-resizable?

    There is a better way:
    Qt Code:
    1. layout()->setSizeConstraint(QLayout::SetFixedSize);
    To copy to clipboard, switch view to plain text mode 
    This way it'll adjust the size when the size hint changes.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what to do to make windows non-resizable?

    It's the same:

    QLayout::SetFixedSize
    The main widget's size is set to sizeHint(); it cannot be resized at all.
    Regards

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

    Default Re: what to do to make windows non-resizable?

    It's not the same. When the size hint changes (for example becomes smaller) my code will resize the widget. Yours won't. One is dynamic, the other is static.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what to do to make windows non-resizable?

    To Wysota:

    Ok, you're right :
    Qt Code:
    1. case SetFixedSize:
    2. // will trigger resize
    3. mw->setFixedSize(totalSizeHint());
    4. break;
    To copy to clipboard, switch view to plain text mode 
    ( it's from qlayout.cpp , in function activate ).

    But I believe both approaches will have the same effect on the attached dialog because from what I can see in the attachments, none of the widgets are resized dynamically, once the dialog is made visible.

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

    Default Re: what to do to make windows non-resizable?

    Quote Originally Posted by marcel View Post
    But I believe both approaches will have the same effect on the attached dialog because from what I can see in the attachments, none of the widgets are resized dynamically, once the dialog is made visible.
    What if the font or language changes?

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what to do to make windows non-resizable?

    OK, you got me

  9. #9
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: what to do to make windows non-resizable?

    Thanks to all who replied.

    I added:

    Qt Code:
    1. layout() -> setSizeConstraint ( QLayout :: SetFixedSize ) ;
    To copy to clipboard, switch view to plain text mode 

    at line 40 of ui.cpp but now I get a very tiny window which shows nothing. I am now unable to resize the window which would be good except I can't see anything at all.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  10. #10
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: what to do to make windows non-resizable?

    I also don't understand why setting the sizePolicy to Fixed isn't enough to do this.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

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

    Default Re: what to do to make windows non-resizable?

    Quote Originally Posted by jamadagni View Post
    I added:

    Qt Code:
    1. layout() -> setSizeConstraint ( QLayout :: SetFixedSize ) ;
    To copy to clipboard, switch view to plain text mode 

    at line 40 of ui.cpp but now I get a very tiny window which shows nothing. I am now unable to resize the window which would be good except I can't see anything at all.
    It probably means you didn't apply a layout to the form or somewhere lower in the hierarchy.


    Quote Originally Posted by jamadagni View Post
    I also don't understand why setting the sizePolicy to Fixed isn't enough to do this.
    Because sizePolicy only works for a widget that is inside a layout and obviously a top-level window (like yours) is not inside one.

  12. #12
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what to do to make windows non-resizable?

    Because your ui doesn't have a layout set.

    I have attached the fixed version. Try it. Should work now...
    I just set a vertical layout to your window.

    Regards.
    Attached Files Attached Files
    Last edited by marcel; 14th April 2007 at 08:58.

  13. The following user says thank you to marcel for this useful post:

    jamadagni (14th April 2007)

  14. #13
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: what to do to make windows non-resizable?

    Thanks it works, but I still have a few questions:

    1. I created the UI file using Designer. Is it a designer bug that it did not create a layout object?

      Should setSizePolicy(Fixed) not be enough to declare the window of fixed-size? After all that is the definition of Fixed:

      QSizePolicy Class Reference:

      QSizePolicy::Fixed : 0 : The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button).
    2. Why does Qt Designer not use this method itself?
    3. Why does Qt Designer by default create a centralWidget(QWidget) and layoutWidget(QVBoxLayout)? What is their use?
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  15. #14
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what to do to make windows non-resizable?

    1. No, it is not a bug. You should layout your widgets.
    As Wysota pointed out, QMainWindow is not a regular widget. It does not have a parent widget, therefore no layout to manage it's size and position.

    2. Not sure what you mean? Do you mean why there isn't an option to set the size constraint? Maybe because the designer doesn't know the actual (runtime) contents of the widgets and this would mix things up ( could give you a wrong preview of the dialog ).

    3. Probably just for preview reasons. But that shouldn't make things worse for you. You can always break the layout and set another one.

    Regards

Similar Threads

  1. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  2. Replies: 10
    Last Post: 25th February 2007, 00:23
  3. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57
  4. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 01:00
  5. Qt and windows vista
    By munna in forum General Discussion
    Replies: 8
    Last Post: 11th January 2006, 22:33

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.