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. Subclass QGraphicsPixmapItem and paint(draw) on pixmap() directly
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.4k 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.
  • J Offline
    J Offline
    jh224
    wrote on last edited by
    #1

    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);
    }@

    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