DrawTest for QT GUI Application(QT波形绘制实例)

根据提供的数组和设定的显示范围进行波形的显示,改变窗口大小,波形和刻度线都会相应改变。

源代码下载 :http://download.csdn.net/source/1963001

关键技术点:

1、从QGraphicsView 类派生自定义的类:“GraphicsView”,重写 resizeEvent(QResizeEvent *) 方法。

class GraphicsView : public QGraphicsView { public: GraphicsView (QWidget * parent = 0); protected: void resizeEvent(QResizeEvent *event) { if (scene()){ scene()->setSceneRect(QRect(QPoint(0, 0), event->size())); } QGraphicsView::resizeEvent(event); } };

2、将根据*.ui文件产生的ui_*.h文件中的

QGraphicsView *graphicsView ;

... ...

graphicsView = new QGraphicsView(gridLayoutWidget );

改成

GraphicsView *graphicsView ;

... ...

graphicsView = new GraphicsView(gridLayoutWidget );

当然还要记得:

#include "GraphicsView.h"

3、要添加QGridLayout *gridLayout ;并将它的parent 指定为 窗体的QWidget,默认是自动生成的gridLayoutWidget

gridLayout = new QGridLayout(DrawTestClass );

4、重写 窗口类的resizeEvent(QResizeEvent *)

 

void DrawTest::resizeEvent(QResizeEvent *event){ QWidget::resizeEvent(event); drawClicked();//绘制函数 }

 

 

5、源代码下载:http://download.csdn.net/source/1963001

你可能感兴趣的:(UI,application,Class,qt)