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 unprecise painting with raster engine
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView unprecise painting with raster engine

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 6.0k 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.
  • H Offline
    H Offline
    Henrik
    wrote on last edited by
    #1

    I have a QGraphicsView with multiple QGraphicsItems. The items draw a QPixmap into the boundingRect of the item and a black line on the border of the boundingRect. If I use the opengl painting engine the border is exactly where the image is painted. With raster engine there is (depending on the size of the graphics item) space between the drawn border and the drawn image. It looks like the sizes are calculated as integers and not as floats. Is there an option to set or a workaround for this painting errors ?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kleimola
      wrote on last edited by
      #2

      Are you zooming the viewport and what is the pen width you're using for the rectangle? Are you moving the item or is it static? Can you give an example?

      >> Johannes <<

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Henrik
        wrote on last edited by
        #3

        I'am zooming the viewport and the drawn rect should be drawn everytime with the same width in every zoom level. This item can be moved and resized, the inaccurate painting is only done in some zoom - size relations.
        @
        // draw the pixmap
        painter->drawPixmap(dataItem()->rect(), pixmap)

        painter->setPen(QPen(Qt::black, 1.0, Qt::DashLine));
        // reset the transformation
        QTransform t(painter->transform());
        painter->resetTransform();
        // get the rect to draw without transformation
        QPolygonF selectedPolygon = t.map(selectedRect);
        painter->drawPolygon(selectedPolygon);

        // draw some other untransformed stuff
        ...
        @

        I thought it is some kind of rounding problem, but with opengl it is exactly this code and it works.
        This is how it looks
        !http://img844.imageshack.us/img844/9009/bildschirmfoto20100720u.png(example)!

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kleimola
          wrote on last edited by
          #4

          I have seen this problem too. You're using size 1.0 pen width, but zooming the viewport scales this too. If one pixel border line is ok, try using 0.0 pen.

          >> Johannes <<

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Henrik
            wrote on last edited by
            #5

            Thank you ! I think I have an error where the selectionRect is calculated.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Henrik
              wrote on last edited by
              #6

              Hmm the selectionRect is correctly calculated. It must have to do something with pixmap drawing.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Henrik
                wrote on last edited by
                #7

                Another thing is that the small rect with the white border is drawn like

                @
                painter->setPen(QPen(Qt::white, 0.0, Qt::SolidLine));
                painter->setBrush(Qt::black);
                painter->drawRect(...);
                @

                as you can see it isn't drawn exactly, too.

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Henrik
                  wrote on last edited by
                  #8

                  I have a workaround for raster engine drawing of black rect with a small white border and deactivated Antialiasing.

                  @
                  qreal borderWidth = 1.0;
                  painter->setPen(Qt::NoPen);
                  painter->setBrush(Qt::white);
                  painter->drawRects(rect);
                  painter->setBrush(Qt::black);
                  painter->drawRects(rect.adjusted(borderWidth, borderWidth, -borderWidth, -borderWidth));
                  @

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kleimola
                    wrote on last edited by
                    #9

                    Did you try your original code with 0.0 pen and antialiasing disabled?

                    >> Johannes <<

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      Henrik
                      wrote on last edited by
                      #10

                      Atialiasing is false and I tried it with 0.0 and 1.0 pen width and it made no difference because the transformation is reseted.

                      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