Issues with drawing in a QGraphicsScene



  • 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.



  • 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.



  • 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.



  • I added the line:

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

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.