Код такой
#include <QtGui>
class myClass : public QGraphicsScene
{
public :
myClass(QObject *parent = 0);
virtual void keyPressEvent(QKeyEvent *event);
private :
QGraphicsEllipseItem *item;
};
myClass::myClass(QObject *parent)
: QGraphicsScene(parent)
{
this->setSceneRect(0,0,600,600);
item = new QGraphicsEllipseItem(0, this);
item->setRect(QRectF(50,50,100,100));
}
void myClass::keyPressEvent(QKeyEvent *event)
{
for(int i = 0; i < 200; i++) {
qDebug() << i;
item->setPos(i, item->y());
sleep(1);
}
}
int main(int argc, char **argv)
{
QApplication app(argc,argv);
myClass m;
QGraphicsView v(&m);
v.setRenderHints( QPainter::Antialiasing );
v.show();
return app.exec();
}