|
对下面这个程序编译运行时,怎么是空白一片呀?为何看不到画的图形呀?请指点,多谢!
main.cpp
//-------------------------------------------------------------------------
#include <qapplication.h>
#include "testpainter.h"
int main( int argc, char **argv )
{
QApplication app ( argc, argv );
TestPainter testPainter ;
app.setMainWidget( &testPainter );
testPainter.show();
testPainter.draw();
testPainter.drawPie();
testPainter.drawCubicBezier();
testPainter.show();
return app.exec();
}
testpainter.h:
//-------------------------------------------------------------------------
#ifndef TESTPAINTER_H
#define TESTPAINTER_H
#include <qwidget.h>
class TestPainter : public QWidget
{
public:
TestPainter( QWidget* parent=0, const char* name=0 );
~TestPainter();
void draw();
void drawPie();
void drawCubicBezier();
};
#endif
testpainter.cpp:
//-------------------------------------------------------------------------
#include <qpainter.h>
#include "testpainter.h"
TestPainter::TestPainter( QWidget* parent, const char* name)
:QWidget(parent, name )
{
}
TestPainter::~TestPainter()
{
}
void TestPainter::draw()
{
QPainter painter (this );
painter.setPen( QPen( black, 8, DashDotLine) );
painter.setBrush( QBrush( red, Dense6Pattern) );
painter.drawEllipse( 20, 20, 100, 60 );
}
void TestPainter::drawPie( )
{
QPainter painter ( this );
painter.setPen( QPen( black, 5, SolidLine) );
painter.setBrush( QBrush( red, Dense1Pattern) );
painter.drawPie( 160, 20, 100, 60, 60 * 16, 270 * 16 );
}
void TestPainter::drawCubicBezier()
{
QPainter painter( this );
QPointArray points( 4 );
points[0] = QPoint( 280, 80 );
points[1] = QPoint( 320, 10 );
points[2] = QPoint( 360, 10 );
points[3] = QPoint( 400, 80 );
painter.setPen( QPen(blue, 2, SolidLine) );
painter.drawCubicBezier( points );
} |
|