|
#include <qapplication.h>
#include <qwidget.h>
#include <qpainter.h>
#include <qpoint.h>
#include <qtimer.h>
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget( QWidget *parent = 0, const char *name = 0 );
protected:
void paintEvent( QPaintEvent * );
private:
QTimer *autoShootTimer;
QRect rect;
int timeout;
int i;
private slots:
void move(void);
};
MyWidget::MyWidget(QWidget *parent, const char *name ) : QWidget(parent, name)
{
autoShootTimer = new QTimer( this, "movement handler" );
connect( autoShootTimer, SIGNAL(timeout()), SLOT(move()) );
rect = QRect(10,10,40,40);
autoShootTimer->start( 50 );
i = 4;
}
void MyWidget::paintEvent(QPaintEvent *)
{
QPainter paint( this);
paint.drawRect(rect);
}
void MyWidget::move()
{
timeout++;
if(timeout>100)
return;
rect = QRect(10+i, 10, 40, 40);
repaint();
}
int main(int argc, char **argv)
{
QApplication a(argc, argv);
MyWidget w;
a.setMainWidget( &w);
w.show();
return a.exec();
}
// i just want the rectangle move autoly. but where is the wrong.? |
|