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. Resizing pixmaps inside QGraphicsScene when the scene is resized
QtWS25 Last Chance

Resizing pixmaps inside QGraphicsScene when the scene is resized

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 5.0k 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.
  • Z Offline
    Z Offline
    zurbek
    wrote on last edited by
    #1

    Hi there!
    I have a window which looks like this : http://imgur.com/tjhpyOX
    What I want to do is a Game of 15 - I have to put multiple images in a grid inside this QGraphicsScene but the thing is, I want them to resize when I resize this window.
    The widgets inside the window resize automatically as they're inside a QGridLayout but I cant get the images inside the QGraphicsScene to resize.
    How do I do that?

    Thanks in advance!

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      you could zoom the graphicsview in the resizeEvent. The following code ensures that the image grid (bounding rect) is always visible inside the graphcisview.
      @
      void MyGraphicsView::resizeEvent(QResizeEvent* event)
      {
      QGraphicsView::resizeEvent(event);

       QSize viewportSize = this->viewport().size();
       QSize imageGridSize = ...; //size of all images (bounding rect)
      
       qreal factor = viewportSize.width() / imageGridSize.width();
       if( viewportSize.height() < (imageGridSize * factor).height() )
          factor *= viewSize.height() / (imageSize * factor).height();
      
       this->resetTransform();
       QTransform transform = this->transform();
             transform.scale(factor, factor);
       this->setTransform(transform);
      

      }
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zurbek
        wrote on last edited by
        #3

        Zooming sounds like a good idea, shouldn't I zoom scene according to graphicsview size though?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          this may work in some cases... but resizing to the viewport's size is the correct way since this is the visible area where your items are rendered onto.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          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