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. [SOLVED] Graphical artefacts in QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Graphical artefacts in QGraphicsScene

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 823 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
    heatblazer
    wrote on last edited by
    #1

    Hello, I am trying to apply animation to one of my objects, but when the animation occurs, there are remaining artefacts. Look at the red triangle on the picture with the "A" in it. There are some kind of afterimages:
    https://www.flickr.com/photos/heatblazer/15989282299/
    Here is the code I use to paint it:
    this overrides paint()
    @
    static inline void paintForA(QPainter* qp,
    const QStyleOptionGraphicsItem* qsi,
    QWidget* wd, QGraphicsItem* ari ) {
    static int frames = 0;
    qDebug() << "paintForA() call";
    QRectF rec = ari->boundingRect();
    QPixmap E_png(":/resources/images/A.png");
    QImage eframe = E_png.toImage();
    qp->drawImage(((ActionRectItem*)ari)->getX(),
    ((ActionRectItem*)ari)->getY(),
    eframe);

    }
    @
    And this is on advance
    @
    static inline void customOnAdvance2(int j, QGraphicsItem* ari) {
    if ( !j ) return;
    static int i = 0;
    if ( i++ > 30 ) i =0;
    if ( i < 15 ) {
    ((QGraphicsRectItem*)ari)->setPos(
    ((QGraphicsRectItem*)ari)
    ->mapToParent(0, (((ActionRectItem*)ari)->getSpeed()-1)));
    } else {
    ((QGraphicsRectItem
    )ari)->setPos(
    ((QGraphicsRectItem*)ari)
    ->mapToParent(0, (((ActionRectItem*)ari)->getSpeed())));

    }
    

    }
    @

    In the main constructor:
    @
    ...
    connect(timer, SIGNAL(timeout()),
    myScene, SLOT(advance()));
    @
    Everything moves, but leaves these afterimages. Is this some kind of double buffernig it or?
    [EDIT] I`ve solved it. It appeared that I must explicitly call QWidget::update() here:
    @

    static inline void paintForA(QPainter* qp,
    const QStyleOptionGraphicsItem* qsi,
    QWidget* wd, QGraphicsItem* ari ) {
    static int frames = 0;
    /* test for static memory */

    qDebug() << "paintForA() call";
    QRectF rec = ari->boundingRect();
    static QPixmap E_png(":/resources/images/A.png");
    static QImage eframe = E_png.toImage();
    qp->drawImage(((ActionRectItem*)ari)->getX(),
                      ((ActionRectItem*)ari)->getY(),
                      eframe);
    

    /* the fix */ wd->update();

    }
    @
    Now the images are gone :) Sorry. Just too fast to self answer.

    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