Subclass QGraphicsPixmapItem and paint(draw) on pixmap() directly



  • I want to create a custom QGraphicsPixmapItem and be able to draw on pixmap() directly. Any Suggestions?

    This is what I want to do:

    @
    void myPixmapItem::drawLineTO(const QPointF &endPoint)
    {
    QPainter painter(&pixmap());
    painter.drawLine(lastPoint, endPoint);
    modified = true;
    int rad = (penWidth /2)+2;
    update(QRect(lastPoint.toPoint(), endPoint.toPoint().normalized().adjusted(-rad, -rad, +rad, +rad);
    lastPoint = endPoint;

    }
    @
    This crashes and I get the following error:
    QPaintDevice: Cannot destroy paint device that is being painted

    This is what works but is sluggish because I have to use a copy.

    @
    created in the header:
    QPixmap pmap;

    In the constructor:
    pmap = pixmap();

    void myPixmapItem::drawLineTO(const QPointF &endPoint)
    {
    QPainter painter(&pmap);
    painter.drawLine(lastPoint, endPoint);
    modified = true;
    int rad = (penWidth /2)+2;
    update(QRect(lastPoint.toPoint(), endPoint.toPoint().normalized().adjusted(-rad, -rad, +rad, +rad);
    lastPoint = endPoint;
    setPixmap(pmap);
    }@


Log in to reply
 

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