Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Set fixed size of QMainWindow created in Designer
QtWS25 Last Chance

Set fixed size of QMainWindow created in Designer

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 90.3k Views
  • 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 Offline
    U Offline
    usamytch
    wrote on 19 Apr 2011, 07:38 last edited by
    #1

    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
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on 19 Apr 2011, 07:59 last edited by
      #2

      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
      0
      • V Offline
        V Offline
        vinb
        wrote on 19 Apr 2011, 08:01 last edited by
        #3

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

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

        1 Reply Last reply
        1
        • U Offline
          U Offline
          usamytch
          wrote on 19 Apr 2011, 08:45 last edited by
          #4

          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
          0
          • M Offline
            M Offline
            marko-a
            wrote on 19 Apr 2011, 08:58 last edited by
            #5

            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
            1
            • V Offline
              V Offline
              vinb
              wrote on 19 Apr 2011, 09:00 last edited by
              #6

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

              edit:
              "this" is not needed.

              1 Reply Last reply
              0
              • U Offline
                U Offline
                usamytch
                wrote on 19 Apr 2011, 09:05 last edited by
                #7

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

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vinb
                  wrote on 19 Apr 2011, 09:07 last edited by
                  #8

                  @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
                  0
                  • Z Offline
                    Z Offline
                    ZapB
                    wrote on 19 Apr 2011, 09:14 last edited by
                    #9

                    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
                    0
                    • M Offline
                      M Offline
                      marko-a
                      wrote on 19 Apr 2011, 09:47 last edited by
                      #10

                      [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
                      0
                      • Z Offline
                        Z Offline
                        ZapB
                        wrote on 19 Apr 2011, 09:53 last edited by
                        #11

                        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
                        0

                        10/11

                        19 Apr 2011, 09:47

                        • Login

                        • Login or register to search.
                        10 out of 11
                        • First post
                          10/11
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved