ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:18.57KB ,
资源ID:10691649      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10691649.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(QT编写动态曲线.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

QT编写动态曲线.docx

1、QT编写动态曲线喜马拉雅-巅峰之作主页博客相册|个人档案 |好友 |i贴吧 查看文章【转】 qt实现实时动态曲线(一)2011年04月19日 星期二 下午 12:39转载自 Linuxzrq最终编辑 Linuxzrqdisplay.h:#ifndef DISPLAY_H#define DISPLAY_H#ifndef QT_H#include #endif / QT_Hclass QTimer;class Screen;class QStringList;class QString;class QLineEdit;class QPushButton;class DisplayWidget :

2、public QWidget Q_OBJECTpublic: DisplayWidget( QWidget *parent=0, const char *name=0 ); QSize sizeHint() const; double readCurveDate(); void readFile(); void run();private slots: void tick(); void start();/startbutton void stop();/stopbuttonprivate: Screen *screen1; QLineEdit *lineEdit;/display curve

3、data QPushButton *startButton, *stopButton; QTimer *timer; enum Margin = 40; QString str; QStringList strlist; QStringList :Iterator it; int time; double yval;#endif / PLOT_Hdisplay.cpp:#include display.h#include screen.h#include #include #include #include #include #include #include #include #includ

4、e #include #include #include using namespace std;DisplayWidget:DisplayWidget( QWidget *parent, const char *name ) : QWidget( parent, name ) timer = 0; QVBoxLayout *vbox = new QVBoxLayout( this, 10 ); QHBoxLayout *hbox = new QHBoxLayout( vbox ); screen1 = new Screen( this ); screen1-setYTitle( QObjec

5、t:tr( dynamic curve ) ); vbox-addWidget( screen1 ); lineEdit = new QLineEdit(this); lineEdit-setReadOnly( TRUE ); hbox-addWidget( lineEdit ); startButton = new QPushButton( this ); startButton-setText( tr( &Start ) ); startButton-setAccel( QKeySequence( tr( Alt+S ) ) ); stopButton = new QPushButton(

6、 this ); stopButton-setText( tr( Sto&p ) ); stopButton-setAccel( QKeySequence( tr( Alt+P ) ) ); hbox-addWidget( startButton ); hbox-addWidget( stopButton ); connect( startButton, SIGNAL( clicked () ), SLOT( start() ) ); connect( stopButton, SIGNAL( clicked () ), SLOT( stop() ) ); time = 0; yval = 0.

7、0; readFile();void DisplayWidget:run() if ( !timer ) timer = new QTimer( this ); connect( timer, SIGNAL( timeout() ), SLOT( tick() ) ); timer-start( 1000 );/delay 1svoid DisplayWidget:tick() yval = readCurveDate(); screen1-animate( yval ); lineEdit-setText( QString:number( yval ) );/display curvedat

8、avoid DisplayWidget:start() run();void DisplayWidget:stop() timer-stop();QSize DisplayWidget:sizeHint() const return QSize( 32 * Margin, 24 * Margin );/read data from filevoid DisplayWidget:readFile() QFile file(in.txt); file.open(QIODevice:ReadOnly); QTextStream in(&file); str = in.read(); strlist

9、= QStringList:split( , str); it = strlist.begin(); double DisplayWidget:readCurveDate( ) QString tempStr; double tempDate; tempStr =(QString) *it; tempDate = tempStr.toDouble(); if (it != strlist.end() +it; else it = strlist.begin(); return tempDate;screen.h:#ifndef SCREEN_H#define SCREEN_H#include

10、#include #include #include #include #include #define FrameWidth 2#define Step 5 #define BaseFontHeight 16#define BaseLineLenght 5 #define SpaceMargin 4class QRect;class QString;class Screen : public QFrame Q_OBJECTpublic: Screen( QWidget *parent=0, const char *name=0, Qt:WFlags flags=0 ); void anima

11、te( double y); void setXTitle( QString str ); void setYTitle( QString str );protected: void initNumber( void ); void initCordinate( QPainter &p ); void updateCurve( QPainter &p ); virtual void showEvent ( QShowEvent * ); virtual void hideEvent ( QHideEvent * ); QSize minimumSize () const;public: dou

12、ble newY, oldY; int numXTicks, numYTicks; QValueVector Yval; bool firstShow; int sec, min, hour; QPixmap saveBuffer, newBuffer, midBuffer; QRect rectCordinate; QRect fromSaveRect; QRect toNewRect; QRect rectYText; QRect rectXText; /*We use this painter to draw evering on the newbuffer.*/ QPainter dr

13、awPainter; QString stringYTitle; QString stringXTitle;#endif /*SCREEN_H*/screen.cpp:#include screen.h#include #include #include #include #include #include #include #include #include #include #include Screen:Screen( QWidget *parent, const char *name, Qt:WFlags flags ): QFrame( parent, name, flags | Q

14、t:WNoAutoErase ) setLineWidth( FrameWidth ); setFrameStyle( Panel | Sunken ); setBackgroundMode( Qt:PaletteBase ); setSizePolicy( QSizePolicy:MinimumExpanding, QSizePolicy:MinimumExpanding ); firstShow = TRUE;void Screen:showEvent( QShowEvent * ) if ( firstShow ) initNumber(); initCordinate( drawPai

15、nter );QSize Screen:minimumSize () const return QSize( 20 * SpaceMargin, 20 * SpaceMargin );void Screen:hideEvent( QHideEvent * ) firstShow = FALSE;void Screen:setXTitle(QString str ) stringXTitle = str;void Screen:setYTitle( QString str ) stringYTitle = str;void Screen:initNumber( ) saveBuffer.resi

16、ze( size() ); /set the size and the backcolor of saveBuffer.fill( this, 0, 0 );/those three QPixmaps as same as the Screen newBuffer.resize( size() ); newBuffer.fill( this, 0, 0 ); midBuffer.resize( size() ); midBuffer.fill( this, 0, 0 ); drawPainter.begin(&newBuffer); QRect newWindow = drawPainter.

17、window(); newY = 0; oldY =0; sec = 0; min = 0; hour = 0; stringXTitle = QObject:tr( Time (hh:mm:ss) ); Yval.push_back( (double)oldY ); rectCordinate.setRect( newWindow.topLeft().x()+FrameWidth + 2 * BaseFontHeight + 2 * BaseLineLenght, newWindow.topLeft().y()+FrameWidth + 2 * SpaceMargin, newWindow.

18、width() - 2 * ( FrameWidth + BaseFontHeight + BaseLineLenght + SpaceMargin ), newWindow.height() - 2 * ( FrameWidth + BaseFontHeight +BaseLineLenght+SpaceMargin ) ); if ( 0 != ( rectCordinate.width() % (Step*Step) ) ) int x = rectCordinate.width() % ( Step * Step ); /( (int) sqrt( (float) Step ) );

19、rectCordinate.setWidth( rectCordinate.width() - x+1 ); if ( 0 != ( rectCordinate.height() % (Step*Step) ) ) int y = rectCordinate.height() % (Step *Step ); rectCordinate.setHeight( rectCordinate.height() - y+1 ); numXTicks = rectCordinate.width() / Step; numYTicks = rectCordinate.height() / Step; re

20、ctYText.setRect(newWindow.topLeft().x() + FrameWidth,newWindow.topLeft().y(+FrameWidth+2 * SpaceMargin,BaseFontHeight, rectCordinate.height() ); rectXText.setRect(rectCordinate.bottomLeft().x(), newWindow.bottomLeft().y() - FrameWidth - BaseFontHeight,rectCordinate.width(), BaseFontHeight ); fromSav

21、eRect.setRect(rectCordinate.topLeft().x() + Step,rectCordinate.topLeft().y() + 1, rectCordinate.width() - Step - 1, rectCordinate.height() + 2 * BaseLineLenght + BaseFontHeight ); toNewRect.setRect(rectCordinate.topLeft().x() + 1,rectCordinate.topLeft().y() + 1, rectCordinate.width() - Step - 1, rec

22、tCordinate.height() + 2 * BaseLineLenght + BaseFontHeight ); drawPainter.drawRect(toNewRect);void Screen:initCordinate( QPainter &pCordinate )if ( firstShow ) pCordinate.setPen( Qt:blue ); pCordinate.drawRect( rectCordinate ); this-setAttribute(Qt:WA_PaintOutsidePaintEvent);/ int y0 = rectCordinate.

23、bottomLeft().y(); int x0 = rectCordinate.bottomLeft().x(); int yText = 0; for (int j = 0; j = numYTicks; j + ) pCordinate.drawLine( x0 - BaseLineLenght, y0, x0, y0 ); if (0 = j % Step ) pCordinate.drawLine( x0 - 2 * BaseLineLenght, y0, x0 - BaseLineLenght, y0 ); pCordinate.save(); pCordinate.setPen(

24、 QPen( Qt:blue, 1, Qt:DotLine) ); pCordinate.drawLine( x0 , y0, rectCordinate.bottomRight().x(), y0 ); pCordinate.restore(); pCordinate.setPen( Qt:black ); pCordinate.drawText( x0 - 2 * BaseLineLenght - BaseFontHeight, y0 - 2 * BaseFontHeight + 5 * Step,BaseFontHeight, BaseFontHeight + Step, Qt:AlignCenter , QString:number( yText) ); yText +=10; pCordinate.setPen( Qt:blue );

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1