hitcounter
dpointer
Tuesday, September 28, 2004
 
Paint Your Form

Answering one question about QPainter in the mailing-list, I gave a short example like below. This is a single-file, Qt-based application, so perhaps you can compile directly and save time by avoiding qmake. The purpose of this small program is very simple, paint a picture, taken from file pic.jpg, to its main window. Of course, to try it you need to supply the JPEG file (could be anything).

#include <qmainwindow.h>
#include <qapplication.h>
#include <qpainter.h>
#include <qpixmap.h>

class PainterExample : public QMainWindow
{
public:
PainterExample();
virtual void paintEvent( QPaintEvent* );
};

PainterExample::PainterExample(): QMainWindow( 0, "painterexample" )
{
}

void PainterExample::paintEvent( QPaintEvent* )
{
QPainter p( this );
p.drawPixmap( 0,0, QPixmap("pic.jpg"),0,0,100,100 );
}

int main( int argc, char ** argv )
{
QApplication a( argc, argv );
QMainWindow* v = new PainterExample( );
v->show();
a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
return a.exec();
}

Comments: Post a Comment

<< Home

Powered by Blogger