QPainterPath对象上的动画

时间:2017-06-28 07:56:05

标签: c++ qt animation qpainterpath

我想显示一个动画箭头形状按钮。

为了绘制它,我创建了一个继承QGraphicsObject并使用QPainterPath类的类。

我在QGraphicsScene中绘制它并使用属性geometry为其设置动画,在MyArrow类中重新定义。

您可以在此处找到所有代码:https://github.com/TaiZzZ/arrowAnimation

我的问题如下:

箭头动画(意味着它向右移动并返回)但在移动时保持绘画。你知道为什么吗?

Ps:我使用QState Machine有相同的行为,所以我猜这个问题只来自我绘制箭头的方式。

我尝试了两件不同的事情:

  • 将贝塞尔曲线更改为直线,无法解决问题。

  • 我没有绘制路径,而是绘制了一个矩形(boundingRect())(所以我只更改了drawPath(path)),并且它可以正常工作

总而言之,该错误来自 QPainterPath ......但为什么?

编辑:

以下图片说明了我的问题:

Before the animation After the animation

请注意,它不再是反联盟的......

1 个答案:

答案 0 :(得分:2)

问题实际上非常简单 - 在重新使用之前,您还没有清除 new Vue({ el:'#filterTest', data:{ keywords:[{"id":"9","name":"missy","phone":"21324234532"}, {"id":"3","name":"Mahama","phone":"345604542"}, {"id":"2","name":"Bernard","phone":"241242542"}] }, computed: { filterM: function () { var self = this return self.filter(function (word) { return user.name.indexOf(self.searchQuery) !== -1 }) } } }); Vue.component('canvas-chat',{ template:'#canvasChart', props:['keywordsData'] })

您的 <script type="text/x-template" id="canvasChart"> <table> <thead> <tr> <th v-for="key.id in keywordsData"> <span class="arrow" ></span> </th> </tr> </thead> <tbody> <tr v-for="key.name in keywordsData"> <td v-for="key.phone in keywordsData"> {{key.name}}</td> </tr> </tbody> </table> </script> <div id="filterTest"> <canvas-chat keywordsData="keywords" ></canvas-chat> </div>班级有会员......

QPainterPath

并且您的Arrow实施以......开头

QPainterPath arrow;

因此,每次调用Arrow::paint时,都会将另一个新子路径添加到arrow.moveTo(rect.right(),rect.center().y()); arrow.lineTo(rect.left(),rect.top()); 。因此,在任何给定时间,您看到的是累积路径。最简单的解决方案是删除Arrow::paint成员变量并使用本地范围的QPainterPath ...

arrow