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. Restrict resize of a Widget.
QtWS25 Last Chance

Restrict resize of a Widget.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicsviewqresizeeventqt 5.7qgraphicssceneresize event
6 Posts 3 Posters 2.4k 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.
  • S Offline
    S Offline
    sayan275
    wrote on 3 Jan 2019, 12:41 last edited by
    #1

    I have Image viewer with some navigation controls.
    0_1546518679742_ImageViewer.jpg
    So, in QGraphicsView there's a QGraphicsScene where I set the image by pixmap.
    Based on the pixmaps width and height, I have restricted the min size of the QGraphicsView as well as the whole widget.
    Now increasing the size of the main widget, it should allow to resize if the width : height ratio matches the image's aspect ratio and the image will scale.
    Let's say my image is 640 : 480, so ratio is 1.3333. Now when I try to resize my ImageViewer, the QGraphicsViewer's new size should have the ratio of 1.333, else the ImageViewer shouldn't resize.
    So, I have overriden resizeEvent(QResizeEvent *event) of the ImageViewer, but I couldn't restrict the resize only on valid conditions. This resizeEvent(QResizeEvent *event) gets called whenever I drag the corners.

    Any suggestions are appreciated!!

    Regards,
    Sayan

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 3 Jan 2019, 14:52 last edited by
      #2

      You can try using the event filters and fix the size once it reaches certain limit.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      S 1 Reply Last reply 8 Jan 2019, 10:06
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 3 Jan 2019, 21:18 last edited by
        #3

        Hi,

        If you want to have a specific aspect ratio, then you should rather handle the resizing in a container widget that would have the ImageViewer as member variable.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        S 1 Reply Last reply 8 Jan 2019, 10:03
        1
        • S SGaist
          3 Jan 2019, 21:18

          Hi,

          If you want to have a specific aspect ratio, then you should rather handle the resizing in a container widget that would have the ImageViewer as member variable.

          S Offline
          S Offline
          sayan275
          wrote on 8 Jan 2019, 10:03 last edited by
          #4

          @SGaist I tried your suggestion, but the resize event gets called after the widget has resized.

          I tried the below, but it fails on start only,-> no widget is visible..it takes size 0,0..so

          double ratio = "1.3";
          double windowRatio = (double) width() / height();
          if(ratio == s)
          {
             QMdiSubWindow::resizeEvent(event);
          }
          else
          {
             resize(event->oldSize());
          }
          
          1 Reply Last reply
          0
          • D dheerendra
            3 Jan 2019, 14:52

            You can try using the event filters and fix the size once it reaches certain limit.

            S Offline
            S Offline
            sayan275
            wrote on 8 Jan 2019, 10:06 last edited by
            #5

            @dheerendra Sir can you explain a bit more in detail.
            Are you asking to installEventFilters for resize event?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 8 Jan 2019, 20:10 last edited by
              #6

              The idea is that you have your container widget getting resized and in its resize event, you change the size of the inner widgets with the ratio you want.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              1/6

              3 Jan 2019, 12:41

              • Login

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