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

    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

  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?

    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

  3. #3
    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?

    Quote Originally Posted by marcel View Post
    1. No, it is not a bug. You should layout your widgets.
    Of course I have laid-out my widgets. See the red line?

    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.
    If that is the case, then it should use its child layout to manage its size, no? A QMainWindow never has a parent widget, but is in need of a size-controller. Ergo it should use the first child size-controller it finds.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  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?

    Of course I have laid-out my widgets. See the red line?
    Yes, but you haven't cvreated a layout for the main window. Look at the ui I attached. The contents of the window stretch to fill the available space when you resize the window.

    If that is the case, then it should use its child layout to manage its size, no? A QMainWindow never has a parent widget, but is in need of a size-controller. Ergo it should use the first child size-controller it finds.
    Yes, use the layout of the window to set it's size. That's why setSizeConstraint worked.

    Regards


  5. #5
    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?

    OK thanks. I also succeeded with just removing the superfluous layoutWidget item and not adding another layout item. There already exists a layout within the layoutWidget item (which is now deleted) which I used. I also did some trimming by removing the SizePolicy items in the UI file since they are not used now.

    A few final questions:

    1. If this is the correct thing to do then why did not Designer do this itself? Is this a bug?
    2. What is the use of the sizePolicy property of the QMainWindow, seeing as setting it to fixed does not give us anything?
    3. Finally, I presume you did the corrections you did using a text editor and not Designer, right?
    Attached Files Attached Files
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  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?

    1. No, I don't believe it's a bug. Looking at the UI the way it is now, you could have done it like this from the beginning.

    2. No effect at all. It's a method from QWidget and applies to a lot of other widgets.

    3. No, I did the correction with Designer. Right click in the form -> Lay out -> Lay out Vertically. No text editor, and you shouldn't use one.

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

    nleverin (11th July 2007)

  8. #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
    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 ).
    Size constraint is an attribute of a layout, not of the widget. I think it would be nice to be able to have such a property in designer just like we have margin and spacing available, but let's face it - how often do you set a size constraint on a layout?

    You can always break the layout and set another one.
    You can't set a new layout for a main window.

    Quote Originally Posted by jamadagni View Post
    If that is the case, then it should use its child layout to manage its size, no?
    No. Layout manages children, not parents. Period. What would happen if you'd wrap a widget with a layout and children into another layout? Which layout should be responsible for managing the size? Besides, you have to have something "fixed" at some point, otherwise you couldn't use size policies as any widget with "expanding" size policy would cause the top level widget to expand to screen width/height.

    A QMainWindow never has a parent widget,
    Why not? I used a QMainWindow as a child widget a few times...

    but is in need of a size-controller. Ergo it should use the first child size-controller it finds.
    The window manager is its controller as it is a child of the root window of your screen.

    Quote Originally Posted by jamadagni View Post
    What is the use of the sizePolicy property of the QMainWindow, seeing as setting it to fixed does not give us anything?
    Designer uses a generic way of managing properties. If you wanted to hide properties which were unusable for top-level widgets, you'd have to have a way of marking any property as such and there would be a problem if you wanted to place one form inside another as the widget which was designed as a top-level widget might in the end be a child of some other widget.

    Finally, I presume you did the corrections you did using a text editor and not Designer, right?
    You should never modify Designer generated files by hand.

  9. #8
    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?

    Quote Originally Posted by wysota View Post
    You should never modify Designer generated files by hand.
    Why never? I realize that it can be labeled not recommended as it is easy to muck up such a complicated XML file, but I have found it a quick way to make tiny tweaks and some cleanups that Designer won't do for me.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  10. #9
    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
    Why never?
    Because of two reasons.
    1. All changes will be overwritten next time you save the file from within Designer,
    2. You have to create a real widget class anyway, so there is no point in modifying any of the generated files as you can do the same elsewhere without pushing yourself into trouble.

    Ok, three reasons...
    3. It's very prone to errors.

    I realize that it can be labeled not recommended
    If you're willing to say that aiming a gun at your head and pressing the trigger is not recommended as well, then I can agree with what you said.

    but I have found it a quick way to make tiny tweaks and some cleanups that Designer won't do for me.
    What kind of tweaks? I don't know if you're referring to modifying xml files saved by Designer or files generated by uic. I guess the former and I really can't see any possible reason to do that...

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.