I'm in a good mood today, so I'll give you ready-made (compilable) solution, if this isn't enough, then you need to go back to the books (you should anyway, most of stuff guys above are saying is in the documentation)
// header
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
{
Q_OBJECT
public:
public slots:
void redrawEllipse( void );
protected:
private:
int radius;
};
#endif // MAINWINDOW_H
// header
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget* parent = 0 );
public slots:
void redrawEllipse( void );
protected:
void paintEvent( QPaintEvent* event );
private:
int radius;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
// implementation
#include "mainwindow.h"
#include <QPainter>
#include <QTimer>
MainWindow
::MainWindow( QWidget* p
) :
radius( 1 )
{
connect( t, SIGNAL( timeout() ), this, SLOT( redrawEllipse() ) );
t->start( 10 );
}
void MainWindow::redrawEllipse( void )
{
radius += 2;
if( radius > qMin( this->width()/2, this->height()/2 ) )
{
radius = 1;
}
this->update();
}
{
Q_UNUSED( e );
p.drawEllipse( this->rect().center(), this->radius, this->radius );
}
// implementation
#include "mainwindow.h"
#include <QPainter>
#include <QTimer>
MainWindow::MainWindow( QWidget* p )
:
QMainWindow( p ),
radius( 1 )
{
QTimer* t = new QTimer( this );
connect( t, SIGNAL( timeout() ), this, SLOT( redrawEllipse() ) );
t->start( 10 );
}
void MainWindow::redrawEllipse( void )
{
radius += 2;
if( radius > qMin( this->width()/2, this->height()/2 ) )
{
radius = 1;
}
this->update();
}
void MainWindow::paintEvent( QPaintEvent* e )
{
Q_UNUSED( e );
QPainter p( this );
p.drawEllipse( this->rect().center(), this->radius, this->radius );
}
To copy to clipboard, switch view to plain text mode
Bookmarks