📄 progress-progress-cpp.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - progress/progress.cpp example file</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align=center>Progress Bar and Dialog Example</h1><br clear="all"> This example displays either a simple (text-only) or a custom-labelled (user-supplied widget) progress dialog. It also demonstrates simple use of menus. <hr> Implementation:<pre>/****************************************************************************** $Id: qt/examples/progress/progress.cpp 2.3.8 edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include <<a name="qprogressdialog.h"></a><a href="qprogressdialog-h.html">qprogressdialog.h</a>>#include <<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>>#include <<a name="qmenubar.h"></a><a href="qmenubar-h.html">qmenubar.h</a>>#include <<a name="qpopupmenu.h"></a><a href="qpopupmenu-h.html">qpopupmenu.h</a>>#include <<a name="qpainter.h"></a><a href="qpainter-h.html">qpainter.h</a>>#include <stdlib.h>class AnimatedThingy : public QLabel {public: AnimatedThingy( <a name="QWidget"></a><a href="qwidget.html">QWidget</a>* parent, const QString& s ) : <a name="QLabel"></a><a href="qlabel.html">QLabel</a>(parent), label(s), step(0) { label+="\n... and wasting CPU\nwith this animation!\n"; for (int i=0; i<nqix; i++) ox[0][i] = oy[0][i] = ox[1][i] = oy[1][i] = 0; x0 = y0 = x1 = y1 = 0; dx0 = rand()%8+2; dy0 = rand()%8+2; dx1 = rand()%8+2; dy1 = rand()%8+2; } void show() { if (!isVisible()) startTimer(100); <a name="show"></a><a href="qwidget.html#200ee5">QWidget::show</a>(); } void hide() { <a name="QWidget::hide"></a><a href="qwidget.html#410481">QWidget::hide</a>(); killTimers(); } <a name="QSize"></a><a href="qsize.html">QSize</a> sizeHint() const { return QSize(120,100); }protected: void timerEvent(<a name="QTimerEvent"></a><a href="qtimerevent.html">QTimerEvent</a>*) { <a name="QPainter"></a><a href="qpainter.html">QPainter</a> p(this); <a name="QPen"></a><a href="qpen.html">QPen</a> pn=p.<a name="pen"></a><a href="qpainter.html#3d26af">pen</a>(); pn.<a name="setWidth"></a><a href="qpen.html#6a009f">setWidth</a>(2); pn.<a name="setColor"></a><a href="qpen.html#00d674">setColor</a>(backgroundColor()); p.<a name="setPen"></a><a href="qpainter.html#0183e4">setPen</a>(pn); step = (step + 1) % nqix; p.<a name="drawLine"></a><a href="qpainter.html#e3a489">drawLine</a>(ox[0][step], oy[0][step], ox[1][step], oy[1][step]); inc(x0, dx0, width()); inc(y0, dy0, height()); inc(x1, dx1, width()); inc(y1, dy1, height()); ox[0][step] = x0; oy[0][step] = y0; ox[1][step] = x1; oy[1][step] = y1; <a name="QColor"></a><a href="qcolor.html">QColor</a> c; c.<a name="setHsv"></a><a href="qcolor.html#e47175">setHsv</a>( (step*255)/nqix, 255, 255 ); // rainbow effect pn.<a href="qpen.html#00d674">setColor</a>(c); p.<a href="qpainter.html#0183e4">setPen</a>(pn); p.<a href="qpainter.html#e3a489">drawLine</a>(ox[0][step], oy[0][step], ox[1][step], oy[1][step]); p.<a href="qpainter.html#0183e4">setPen</a>(colorGroup().text()); p.<a name="drawText"></a><a href="qpainter.html#0f088f">drawText</a>(rect(), AlignCenter, label); } void paintEvent(<a name="QPaintEvent"></a><a href="qpaintevent.html">QPaintEvent</a>* event) { <a href="qpainter.html">QPainter</a> p(this); <a href="qpen.html">QPen</a> pn=p.<a href="qpainter.html#3d26af">pen</a>(); pn.<a href="qpen.html#6a009f">setWidth</a>(2); p.<a href="qpainter.html#0183e4">setPen</a>(pn); p.<a name="setClipRect"></a><a href="qpainter.html#898839">setClipRect</a>(event-><a name="rect"></a><a href="qpaintevent.html#2d6e18">rect</a>()); for (int i=0; i<nqix; i++) { <a href="qcolor.html">QColor</a> c; c.<a href="qcolor.html#e47175">setHsv</a>( (i*255)/nqix, 255, 255 ); // rainbow effect pn.<a href="qpen.html#00d674">setColor</a>(c); p.<a href="qpainter.html#0183e4">setPen</a>(pn); p.<a href="qpainter.html#e3a489">drawLine</a>(ox[0][i], oy[0][i], ox[1][i], oy[1][i]); } p.<a href="qpainter.html#0183e4">setPen</a>(colorGroup().text()); p.<a href="qpainter.html#0f088f">drawText</a>(rect(), AlignCenter, label); }private: void inc(int& x, int& dx, int b) { x+=dx; if (x<0) { x=0; dx=rand()%8+2; } else if (x>=b) { x=b-1; dx=-(rand()%8+2); } } enum {nqix=10}; int ox[2][nqix]; int oy[2][nqix]; int x0,y0,x1,y1; int dx0,dy0,dx1,dy1; <a name="QString"></a><a href="qstring.html">QString</a> label; int step;};class CPUWaster : public QWidget{ Q_OBJECT enum { first_draw_item = 1000, last_draw_item = 1006 }; int drawItemRects(int id) { int n = id - first_draw_item; int r = 100; while (n--) r*=(n%3 ? 5 : 4); return r; } <a href="qstring.html">QString</a> drawItemText(int id) { <a href="qstring.html">QString</a> str; str.<a name="sprintf"></a><a href="qstring.html#926f67">sprintf</a>("%d Rectangles", drawItemRects(id)); return str; }public: CPUWaster() : pb(0) { menubar = new <a name="QMenuBar"></a><a href="qmenubar.html">QMenuBar</a>( this, "menu" ); CHECK_PTR( menubar ); <a name="QPopupMenu"></a><a href="qpopupmenu.html">QPopupMenu</a>* file = new <a href="qpopupmenu.html">QPopupMenu</a>(); CHECK_PTR( file ); menubar-><a name="insertItem"></a><a href="qmenudata.html#deddb9">insertItem</a>( "&File", file ); for (int i=first_draw_item; i<=last_draw_item; i++) file-><a href="qmenudata.html#deddb9">insertItem</a>( drawItemText(i), i ); connect( menubar, SIGNAL(activated(int)), this, SLOT(doMenuItem(int)) ); file-><a name="insertSeparator"></a><a href="qmenudata.html#e34b79">insertSeparator</a>();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -