QT学习之路 - Graphics View Framework(30)

930阅读 0评论2011-07-22 001xiaofei
分类:

工程代码: 30.rar  
http://devbean.blog.51cto.com/448512/241186


  1. #include <QApplication>
  2. #include <QWidget>
  3. #include <QPainter>
  4. #include <QGraphicsScene>
  5. #include <QGraphicsView>

  6. class DrawApp : public QWidget
  7. {
  8. public:
  9.     DrawApp();
  10. protected: //重写 事件函数
  11.     void paintEvent(QPaintEvent *event);
  12. };

  13. DrawApp::DrawApp()
  14. {

  15. }

  16. void DrawApp::paintEvent(QPaintEvent *event)
  17. {
  18.     QPainter painter(this);
  19.     painter.drawLine(10,10,150,300);
  20. }

  21. int main(int argc, char *argv[])
  22. {
  23.     QApplication app(argc, argv);
  24.     QGraphicsScene *scene = new QGraphicsScene;
  25.     scene->addLine(10,10,150,300);
  26.     QGraphicsView *view = new QGraphicsView(scene);
  27.     view->resize(500,500);
  28.     view->setWindowTitle("Graphics View");
  29.     view->show();

  30.     DrawApp *da = new DrawApp;
  31.     da->resize(500,500);
  32.     da->setWindowTitle("Qwidget");
  33.     da->show();

  34.     return app.exec();
  35. }




上一篇:tar 命令
下一篇:Linux内核移植