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. Proper resetting the transformation
Forum Updated to NodeBB v4.3 + New Features

Proper resetting the transformation

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 474 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.
  • J Offline
    J Offline
    jan-tosovsky
    wrote on last edited by
    #1

    In my simple image viewer the image can be panned/zoomed and also fitted to the available width/height. I am facing the problem with fitting the image to the available height (by pressing H key). It works initially, but once the image is zoomed/panned, the image is not centered when fitted any more. While I perform resetting the transformations of both the QGraphicsView and QtWidgets.QGraphicsPixmapItem(), this operation seems to be insufficient.
    The full code is here https://github.com/drifted-in/jet-browser-qt-for-python/blob/main/jetbrowser.py
    Any clue what is missing in my code?

    1 Reply Last reply
    0
    • J jan-tosovsky

      @JoeCFD Thanks, it works nicely with a small tweak (scaling the image width):
      x = (graphics_view.width() - scale * image_rect.width()) * 0.5

      However, it still unclear why resetting the transform doesn't reset the viewport to the initial state when it works without this extra translation.

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #4

      @jan-tosovsky after resize event, the image position has to be adjusted for center alignment. Otherwise, its position will not change.

      1 Reply Last reply
      0
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #2

        add image.setPos(graphics_view.mapToScene(x, 0))
        x = ( graphics_view.size().width() - image.size().width() ) * 0.5

        J 1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          add image.setPos(graphics_view.mapToScene(x, 0))
          x = ( graphics_view.size().width() - image.size().width() ) * 0.5

          J Offline
          J Offline
          jan-tosovsky
          wrote on last edited by
          #3

          @JoeCFD Thanks, it works nicely with a small tweak (scaling the image width):
          x = (graphics_view.width() - scale * image_rect.width()) * 0.5

          However, it still unclear why resetting the transform doesn't reset the viewport to the initial state when it works without this extra translation.

          JoeCFDJ 1 Reply Last reply
          0
          • J jan-tosovsky

            @JoeCFD Thanks, it works nicely with a small tweak (scaling the image width):
            x = (graphics_view.width() - scale * image_rect.width()) * 0.5

            However, it still unclear why resetting the transform doesn't reset the viewport to the initial state when it works without this extra translation.

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #4

            @jan-tosovsky after resize event, the image position has to be adjusted for center alignment. Otherwise, its position will not change.

            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