#include<QApplication>
#include <QWidget>
#include <QPainter>
class MyMainWindow:public QWidget
{
public:
MyMainWindow(QWidget *parent = 0);
private:
void paintEvent(QPaintEvent*);
QPainter *paint;
};
void MyMainWindow::paintEvent(QPaintEvent*)
//paintEvent函数由系统自动调用,用不着我们人为的去调用。
{
paint=new QPainter;
paint->begin(this);
paint->setPen(QPen(Qt::blue,4,Qt::DashLine));//设置画笔形式
paint->setBrush(QBrush(Qt::red,Qt::SolidPattern));//设置画刷形式
paint->drawRect(20,20,160,160);
paint->end();
}
MyMainWindow::MyMainWindow(QWidget*parent):QWidget(parent)
{
setGeometry(100,100,200,200);
}
int main(int argc,char**argv)
{