引用第3楼dbzhang800于2009-09-24 19:50发表的 :
不清楚你的 “move()中的移动是分了两步或更多” 是个什么概念,如果可能你可以贴出来部分代码
不还意思,没表达清楚。
point.h:
class Point:
public QGraphicsItem,
public QObject
{
//Q_OBJECT
public:
Point(void);
~Point(void);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void timerEvent(QTimerEvent *event);
private:
qreal angle;
QColor color;
protected:
void advance(int step);
};
double x,y;
Point.cpp:
#include "Point.h"
Point::Point(void): angle(0),color(qrand() % 256, qrand() % 256, qrand() % 256)
{
startTimer(500);
}
Point::~Point(void)
{
}
void Point::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->setBrush(Qt::red);
QPainterPath path(QPointF(0, 0));
... painter->drawPath(path);
}
QRectF Point::boundingRect() const
{
...
}
QPainterPath Point::shape() const
{
...
}
void Point::timerEvent( QTimerEvent *event )
{
setPos(x,y);
}
main.cpp:
void move(){
x=10,y=10;//step1
delay(10s);
x=20,y=20;//step2
delay(10s);
}
int main(){
x=0,y=0;
move();
return 0;
}
问题是我想让它在step1之后就刷新,该怎么改?