[solved] QDeclarativeItem does not repaint even when I call update()



  • Hi,

    I draw a semicircle with the QPainterPath class. After that I add it to my QML file to show it. So long everything's fine.

    But when I change the sweepLength of the circle and call the update() to force a repaint, nothing happens.
    There is another qml component which lays in front of the circle in qml which moves with an animation. Maybe this causes Qt not to repaint?? Or maybe the repaint comes to early??
    When I switch between my windows and switch back to my QML application, the circle gots repainted just as i wanted it to.

    I paint the circle with the following code:

    @
    void HalfCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    QColor color(Qt::black);
    QPen pen(color, 2);

    QPainterPath myPath;
    myPath.arcMoveTo(0, 0, width(), height(), startAngle());
    myPath.arcTo(QRectF(0, 0, width(), height()), startAngle(), sweepLength());
    
    painter->setPen( pen);
    painter->drawPath(myPath);
    

    }
    @

    width, height, startAngle and sweepLength are properties I can change in qml.

    Anyone an idea why he won't repaint? I call the update(boundingRect()) everytime when one of my properties changes and I call it explicit from inside qml after I changed the properties.


  • Moderators

    If i understand you correctly, you have used the Q_Property macro for the sweeplength and other properties. You also defined the getter and setter in which you call update()?



  • sweeplength etc. is defined with Q_PROPERTY. updateCircle is defined as slot and calls just update to repaint. The method gets called but the repainting is somewhat weired. Parts get rendered, but not everything and not with every angle. Looks much like a bug to me.

    I changed the paint to use the painter->drawArc method instead of the QPainterPath, but the effect is still the same.



  • The remaining problem is, that I have an object (an image) laying over my semi circle I've painted in Qt. My circle doesn't change it's values and the image rotates around a semi circle (it's an gauge). Now there are positions, where my semi circle from Qt gets rendered correct, and others where it doesn't and I don't know why.

    Some parts of my semi circle are still renderes while others aren't, such as if another object is in front of it.

    Nobody an idea what this could be?



  • I've debugged a bit. There I found out, that my updateCircle() slot gets called, before!! my animation took place.
    I have a SequentialAnimation which looks like the following snippet:
    @
    SequentialAnimation {
    id: animation
    loops: Animation.Infinite
    PropertyAction{}
    PropertyAction{}
    NumberAnimation{}
    onCompleted: circle.updateCircle()
    }
    @

    So my thought was, that the completed signal gets emitted, after!! the animation finished. But it seems that it gets called before it finished (The debugger called the updateCircle method, and after that the animated component moved to it's final position and no new repaint took place, which would be needed at this point).

    EDIT:
    I just found out, that the onCompleted slot doesn't get called when the animation stops. Instead it gets called when the next time the animation starts. So the first animation doesn't call this slot, but the second one calls it just at the beginning and after that the animation starts.



  • Hi,

    ok problem solved.

    The loops: Animation.Infinite caused the problem. I needed to change it to loops: 1 (which means I can leave it out because this is it's default value). After that onCompleted gets called when it should.


Log in to reply
 

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