http://devbean.blog.51cto.com/448512/241186
- #include <QApplication>
-
#include <QWidget>
-
#include <QPainter>
-
#include <QGraphicsScene>
-
#include <QGraphicsView>
-
-
class DrawApp : public QWidget
-
{
-
public:
-
DrawApp();
-
protected: //重写 事件函数
-
void paintEvent(QPaintEvent *event);
-
};
-
-
DrawApp::DrawApp()
-
{
-
-
}
-
-
void DrawApp::paintEvent(QPaintEvent *event)
-
{
-
QPainter painter(this);
-
painter.drawLine(10,10,150,300);
-
}
-
-
int main(int argc, char *argv[])
-
{
-
QApplication app(argc, argv);
-
QGraphicsScene *scene = new QGraphicsScene;
-
scene->addLine(10,10,150,300);
-
QGraphicsView *view = new QGraphicsView(scene);
-
view->resize(500,500);
-
view->setWindowTitle("Graphics View");
-
view->show();
-
-
DrawApp *da = new DrawApp;
-
da->resize(500,500);
-
da->setWindowTitle("Qwidget");
-
da->show();
-
-
return app.exec();
- }