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. QGraphicsView resizing

QGraphicsView resizing

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicsviewqgraphicsscenescaling
6 Posts 4 Posters 2.5k 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.
  • M Offline
    M Offline
    MrBolton
    wrote on 13 Jun 2016, 14:16 last edited by MrBolton
    #1

    Hello people,

    I created a custom class, which inherits QGraphicsView to set a background (which I draw myself in another class that inherits from QGraphicsScene, because QGraphicsView::setBackroundBrush() draws the image as a pattern). I want the QGraphicsView to be the exact size of the image I'm passing to the setter, so I did something like this:

    void GridView::setBackgroundImage(const QImage &image)
    {
        m_scene->setBackgroundImage(image);
        setSceneRect(image.rect());
        setFixedSize(image.rect());
        redrawGrid();
    }
    

    However, the image gets cropped from the right side and the bottom. I currently draw the image like this:

    void GridScene::drawBackground(QPainter *painter, const QRectF &rect)
    {
        Q_UNUSED(rect)
        painter->drawImage(sceneRect(), m_backgroundImage, m_backgroundImage.rect());
    }
    

    but I used different parameters as well, with no luck.

    It may be important to mention that I call the following method on the view, so that I have a coordinate system which starts at the top left corner:

    setAlignment(Qt::AlignTop | Qt::AlignLeft);
    

    Am I missing something about the Graphics View Coordinate System or is it something else I'm doing wrong?
    I'm also open for different approaches to prevent the image from scaling to a wrong ratio. Any help is appreciated!

    Tobi

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 13 Jun 2016, 14:32 last edited by mrjj
      #2

      Hi
      QRect has feature:

      http://doc.qt.io/qt-5/qrect.html

      Note that for historical reasons the values returned by the bottom() and right() functions deviate from the true bottom-right corner of the rectangle: The right() function returns left() + width() - 1 and the bottom() function returns top() + height() - 1. The same is the case for the point returned by the bottomRight() convenience function. In addition, the x and y coordinate of the topRight() and bottomLeft() functions, respectively, contain the same deviation from the true right and bottom edges.

      so if u are missing like a pixel in right side, that could be it :)

      1 Reply Last reply
      3
      • M Offline
        M Offline
        MrBolton
        wrote on 14 Jun 2016, 06:42 last edited by
        #3

        Thanks for your answer! Unfortunately it's more than a pixel that I'm missing :/
        But you have a point anyway, so I might add those pixels to the scene rect.

        1 Reply Last reply
        1
        • V Offline
          V Offline
          Vicky Sharma
          wrote on 14 Jun 2016, 06:49 last edited by
          #4

          Hi to all, i am stuck in qml, if someone knows how can resolve below issue will great to me?

          I have a tableview with three columns, inside third column i used button with image on every cell of the same, when user pressed it's image source change from red to green that is fine else red.

          The problem if i am updating my model on every 1 min so before updating it get to cleared and insert again in model successfully but during this all cell's button again goes red in view which was green, so please let me know how can resolve the same?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tekojo
            wrote on 14 Jun 2016, 07:08 last edited by
            #5

            @Vicky-Sharma please start a new topic about your question, and do not post it to other topics that are not related.
            When you have your own topic people will find it and are then more likely to help.

            1 Reply Last reply
            3
            • V Offline
              V Offline
              Vicky Sharma
              wrote on 14 Jun 2016, 07:11 last edited by
              #6

              ok will do

              1 Reply Last reply
              0

              2/6

              13 Jun 2016, 14:32

              4 unread
              • Login

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