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. Proportionnal resizing of window

Proportionnal resizing of window

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.7k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Misty River
    wrote on last edited by
    #1

    Hi,

    I would like my window to resize by keeping horizontal/vertical ratio the same.. Like when I grab the right edge of the window it also resize vertically and vice-versa.. I try overloading the resizeEvent method but at best I get horrible flickers due to the recursion.. What is the appropriate way to do this in a clean manner?

    Thx

    1 Reply Last reply
    0
    • A Offline
      A Offline
      adolby
      wrote on last edited by
      #2

      I'm assuming that the infinite recursion you're experiencing is because you call this->resize() inside of of a widget's resizeEvent. You should override the resizeEvent of the parent of the widget you want to resize. This is because a QResizeEvent is delivered to a widget in response to that same widget being resized, and is designed to allow a widget to respond to the size change by updating its children/members.

      Alternatively, you could create your own layout manager class that sizes its children by percentage. You can possibly adapt the "Border Layout Example":http://qt-project.org/doc/qt-5/qtwidgets-layouts-borderlayout-example.html to get the effect you're looking for.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ankursaxena
        wrote on last edited by
        #3

        Hi,

        Since there is already an option to resize the window through grabing the right edge of the window. then, why you want to do it again ??

        In my point of view,
        And if it is must to do this. then you just have to put conditions in resizeEvent .

        ( If height is not equal to old height then change width according to height difference.

        or

        If width is not equal to old width then change height according to width difference.)

        Such kind of logic you should put in resizeEvent.

        I hope it help.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Misty River
          wrote on last edited by
          #4

          The Widget I want to keep ratio the same is the main window... not a child widget.. and yes I do call this->resize() in the resizeEvent... I don't get infinite recursion, but the event gets called for every pixel change which create very ugly flickers..

          [quote author="adolby" date="1402361318"]I'm assuming that the infinite recursion you're experiencing is because you call this->resize() inside of of a widget's resizeEvent. You should override the resizeEvent of the parent of the widget you want to resize. This is because a QResizeEvent is delivered to a widget in response to that same widget being resized, and is designed to allow a widget to respond to the size change by updating its children/members.

          Alternatively, you could create your own layout manager class that sizes its children by percentage. You can possibly adapt the "Border Layout Example":http://qt-project.org/doc/qt-5/qtwidgets-layouts-borderlayout-example.html to get the effect you're looking for.[/quote]

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Misty River
            wrote on last edited by
            #5

            That's exactly what I did... read what I said again... and I said when I grab the right edge I want the window to resize vertically as well as horizontally ..

            [quote author="ankursaxena" date="1402375559"]Hi,

            Since there is already an option to resize the window through grabing the right edge of the window. then, why you want to do it again ??

            In my point of view,
            And if it is must to do this. then you just have to put conditions in resizeEvent .

            ( If height is not equal to old height then change width according to height difference.

            or

            If width is not equal to old width then change height according to width difference.)

            Such kind of logic you should put in resizeEvent.

            I hope it help.

            [/quote]

            1 Reply Last reply
            0
            • A Offline
              A Offline
              adolby
              wrote on last edited by
              #6

              I'm sorry, I misread your requirements slightly. You want to maintain aspect ratio on your main window. I don't think that this is possible.

              However, it's easy to achieve a similar effect. You can resize child widgets and keep their aspect ratio, as I suggested earlier: override resizeEvent() in your main window to update child widget size. You could also override the heightForWidth() method. Additionally, there is a layout manager class you could use called QSingleItemSquareLayout which can be found among Nokia's example code.

              Here is a StackOverflow thread addressing your question:
              http://stackoverflow.com/q/452333/1583123

              Here is another StackOverflow thread showing heightForWidth() method override:
              http://stackoverflow.com/q/7259847/1583123

              You can find QSingleItemSquareLayout here: http://developer.nokia.com/community/wiki/Archived:Maintaining_square_form_for_a_QWidget

              1 Reply Last reply
              0

              • Login

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