Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Set fixed size of QMainWindow created in Designer

    General and Desktop
    4
    11
    80230
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • U
      usamytch last edited by

      Good day, colleagues!

      How can I fix size of QMainWindow created in Designer? Fix size means that I want to see main window as I created it in Designer without ability to resize.

      I've tried this:

      @ui->setupUi(this);
      centralWidget()->layout()->setSizeConstraint(QLayout::SetFixedSize);@

      But got segfault.

      1 Reply Last reply Reply Quote 0
      • Z
        ZapB last edited by

        To fix the size of the main window itself just call:

        @setFixedSize( myDesiredSize );@

        It's a member of QWidget which of course QMainWIndow inherits.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply Reply Quote 0
        • V
          vinb last edited by

          try this:
          this->setFixedSize(500,500);

          edit:
          didnt noticed that you allready gave the answer ZapB. :)

          1 Reply Last reply Reply Quote 1
          • U
            usamytch last edited by

            Thank you very much, this works, but is there any way to automatically get myDesiredSize from Designer?

            With current solution I should manually copy width and height values from Designer MainWindow geometry.

            1 Reply Last reply Reply Quote 0
            • M
              marko-a last edited by

              Did you try to set both maximum and minimum size in Designer? Right click on your main form and select Size Constraints -> Set Minimum Size and then Size Constraints -> Set Maximum Size.

              1 Reply Last reply Reply Quote 1
              • V
                vinb last edited by

                try this:
                @ this->setFixedSize(this->geometry().width(),this->geometry().height());@

                edit:
                "this" is not needed.

                1 Reply Last reply Reply Quote 0
                • U
                  usamytch last edited by

                  Thank you, both solutions work, but to my mind, second is more elegant.

                  1 Reply Last reply Reply Quote 0
                  • V
                    vinb last edited by

                    @marko-a,
                    Its possible to set your maxsize the same as your minsize, but why do that if you have a nice function (setFixedSize) for it to do the job?

                    1 Reply Last reply Reply Quote 0
                    • Z
                      ZapB last edited by

                      You can also get the preferred size from the sizeHint() functionality and use that as the argument in the setFixedSize() call. That way if your central widget ever changes your app will automatically calculate the new preferred size - as long as the central widget implements a sensible sizeHint of course.

                      Nokia Certified Qt Specialist
                      Interested in hearing about Qt related work

                      1 Reply Last reply Reply Quote 0
                      • M
                        marko-a last edited by

                        [quote author="vinb" date="1303204074"]@marko-a,
                        Its possible to set your maxsize the same as your minsize, but why do that if you have a nice function (setFixedSize) for it to do the job?[/quote]

                        True, but the original question was:

                        [quote author="usamytch" date="1303198694"]
                        How can I fix size of QMainWindow created in Designer? Fix size means that I want to see main window as I created it in Designer without ability to resize.
                        [/quote]

                        Thus if you wish to solve problem by using only Designer you can do so by setting minimum & maximum size constraints.

                        Cheers!

                        1 Reply Last reply Reply Quote 0
                        • Z
                          ZapB last edited by

                          They are both valid solutions. In fact they amount to the same thing since that is all that the setFixedSize() function does anyway.

                          Nokia Certified Qt Specialist
                          Interested in hearing about Qt related work

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post