#include "my_paint_widget.h"int main (int argc, char **argv){ QApplication a(argc, argv); My_Paint_Widget *w=new My_Paint_Widget(); a.setMainWidget(w); w->show(); return a.exec();}
#ifndef MY_PAINT_WIDGET_H#define MY_PAINT_WIDGET_H#include <qwidget.h>class My_Paint_Widget:public QWidget{protected: virtual void paintEvent ( QPaintEvent * ) ; };#endif
#include "my_paint_widget.h"#include <qpainter.h>#include <qbrush.h>#include <qpen.h>#include <qfont.h>#include <qcolor.h>void My_Paint_Widget::paintEvent ( QPaintEvent * e) { QPainter p; QPen pen(QColor(Qt::red), 2); p.begin(this); p.setPen(pen); p.drawLine(10,20,60,60); p.end();}