Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] QDeclarativeItem does not repaint even when I call update()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 3.5k 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.
  • X Offline
    X Offline
    xardas008
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      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()?

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xardas008
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xardas008
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xardas008
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xardas008
              wrote on last edited by
              #6

              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.

              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