scribble-example.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 366 行 · 第 1/2 页
HTML
366 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/examples/scribble/scribble.doc:5 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Simple Painting Application</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: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Simple Painting Application</h1> <p> This example implements the famous scribble example. You can draw aroundin the canvas with different pens and save the result as picture.<p> <hr><p> Header file:<p> <pre>/****************************************************************************** $Id: qt/scribble.h 3.0.5 edited Oct 12 2001 $**** 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.*******************************************************************************/#ifndef SCRIBBLE_H#define SCRIBBLE_H#include <<a href="qmainwindow-h.html">qmainwindow.h</a>>#include <<a href="qpen-h.html">qpen.h</a>>#include <<a href="qpoint-h.html">qpoint.h</a>>#include <<a href="qpixmap-h.html">qpixmap.h</a>>#include <<a href="qwidget-h.html">qwidget.h</a>>#include <<a href="qstring-h.html">qstring.h</a>>#include <<a href="qpointarray-h.html">qpointarray.h</a>>class QMouseEvent;class QResizeEvent;class QPaintEvent;class QToolButton;class QSpinBox;class Canvas : public <a href="qwidget.html">QWidget</a>{ <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>public: Canvas( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0 ); void setPenColor( const <a href="qcolor.html">QColor</a> &c )<a name="x923"></a> { pen.<a href="qpen.html#setColor">setColor</a>( c ); } void setPenWidth( int w )<a name="x924"></a> { pen.<a href="qpen.html#setWidth">setWidth</a>( w ); } <a href="qcolor.html">QColor</a> penColor()<a name="x922"></a> { return pen.<a href="qpen.html#color">color</a>(); } int penWidth()<a name="x925"></a> { return pen.<a href="qpen.html#width">width</a>(); } void save( const <a href="qstring.html">QString</a> &filename, const <a href="qstring.html">QString</a> &format ); void clearScreen();protected: void mousePressEvent( <a href="qmouseevent.html">QMouseEvent</a> *e ); void mouseReleaseEvent( <a href="qmouseevent.html">QMouseEvent</a> *e ); void mouseMoveEvent( <a href="qmouseevent.html">QMouseEvent</a> *e ); void resizeEvent( <a href="qresizeevent.html">QResizeEvent</a> *e ); void paintEvent( <a href="qpaintevent.html">QPaintEvent</a> *e ); <a href="qpen.html">QPen</a> pen; <a href="qpointarray.html">QPointArray</a> polyline; bool mousePressed; <a href="qpixmap.html">QPixmap</a> buffer;};class Scribble : public <a href="qmainwindow.html">QMainWindow</a>{ Q_OBJECTpublic: Scribble( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0 );protected: Canvas* canvas; <a href="qspinbox.html">QSpinBox</a> *bPWidth; <a href="qtoolbutton.html">QToolButton</a> *bPColor, *bSave, *bClear;protected slots: void slotSave(); void slotColor(); void slotWidth( int ); void slotClear();};#endif</pre><p> <hr><p> Implementation:<p> <pre>/****************************************************************************** $Id: qt/scribble.cpp 3.0.5 edited Oct 12 2001 $**** 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 "scribble.h"#include <<a href="qapplication-h.html">qapplication.h</a>>#include <<a href="qevent-h.html">qevent.h</a>>#include <<a href="qpainter-h.html">qpainter.h</a>>#include <<a href="qtoolbar-h.html">qtoolbar.h</a>>#include <<a href="qtoolbutton-h.html">qtoolbutton.h</a>>#include <<a href="qspinbox-h.html">qspinbox.h</a>>#include <<a href="qtooltip-h.html">qtooltip.h</a>>#include <<a href="qrect-h.html">qrect.h</a>>#include <<a href="qpoint-h.html">qpoint.h</a>>#include <<a href="qcolordialog-h.html">qcolordialog.h</a>>#include <<a href="qfiledialog-h.html">qfiledialog.h</a>>#include <<a href="qcursor-h.html">qcursor.h</a>>#include <<a href="qimage-h.html">qimage.h</a>>#include <<a href="qstrlist-h.html">qstrlist.h</a>>#include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>#include <<a href="qintdict-h.html">qintdict.h</a>>const bool no_writing = FALSE;<a name="f335"></a>Canvas::Canvas( <a href="qwidget.html">QWidget</a> *parent, const char *name ) : <a href="qwidget.html">QWidget</a>( parent, name, WStaticContents ), pen( Qt::red, 3 ), polyline(3), mousePressed( FALSE ), buffer( <a href="qwidget.html#width">width</a>(), height() ){<a name="x927"></a><a name="x926"></a> if ((qApp-><a href="qapplication.html#argc">argc</a>() > 0) && !buffer.load(qApp-><a href="qapplication.html#argv">argv</a>()[1])) buffer.fill( <a href="qwidget.html#colorGroup">colorGroup</a>().base() ); <a href="qwidget.html#setBackgroundMode">setBackgroundMode</a>( QWidget::PaletteBase );#ifndef QT_NO_CURSOR <a href="qwidget.html#setCursor">setCursor</a>( Qt::crossCursor );#endif}void <a name="f336"></a>Canvas::save( const <a href="qstring.html">QString</a> &filename, const <a href="qstring.html">QString</a> &format ){ if ( !no_writing )<a name="x963"></a> buffer.save( filename, format.<a href="qstring.html#upper">upper</a>() );}void <a name="f337"></a>Canvas::clearScreen(){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?