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. Issues with drawing in a QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

Issues with drawing in a QGraphicsScene

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

    I'm working on an animation application right now and I have this cursor that is represented by a QGraphics Object. I'm doing it in PyQt4, but the Qt code is pretty much 1:1 with the C++ version. Here is the code for drawing it:

    @
    def init(self, scene=None, parent=None):
    # ...
    points = [
    QPoint(0, 0),
    QPoint(10, 0),
    QPoint(10, 2),
    QPoint(5, 7),
    QPoint(0, 2)
    ]
    self.cursorPoly = QPolygonF(points)
    @

    @ def paint(self, painter, option, widget=None):
    # Draw the cursor
    painter.setPen(QPen(Qt.black))
    painter.setBrush(QBrush(Qt.white))
    painter.drawPolygon(self.cursorPoly)

        # Draw the red line
        painter.setPen(QPen(Qt.red))
        painter.setBrush(QBrush(Qt.NoBrush))
        painter.drawLine(QPoint(5, 7), QPoint(5, FrameMark.MARK_HEIGHT))
    

    @

    When I have a QGraphicsView render the object in a scale of (1,1), it looks like this:
    !http://i.imgur.com/5lS9sSJ.png(bad)!

    This is what it looks like when the QGraphicsView is in a scale of (2,2):
    !http://i.imgur.com/mAyIDEg.png(okay)!

    This is what I'm trying to achive:
    !http://i.imgur.com/3qVhVUu.png(best)!

    I'd prefer to do this without loading up the later image, though that is certainly possible. I also don't have any render hints set for the painter for the QGraphicsView.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      If I understood you correctly, you want an item that ignores the scaling factor? Try setFlag(QGraphicsItem::ItemIgnoresTransformations) and see if that does what you need.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cuddlykittens11
        wrote on last edited by
        #3

        I should have clarified. The first and third images are completely different. The second is what I want it to look like, except that it's scalled up. The shapes of the while parts are different.

        I think it has something to do with the painting coordniate system.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cuddlykittens11
          wrote on last edited by
          #4

          I added the line:

          @painter.transte(QPointF(0.5, 0.5))@

          and now it looks how I want it. I find this very odd.

          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