cursor-example.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 186 行
HTML
186 行
<!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/cursor/cursor.doc:4 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Cursors</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>Cursors</h1> <p> This example shows how to set a mouse cursor for a widget.<p> <hr><p> Implementation:<p> <pre>/****************************************************************************** $Id: qt/cursor.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 <<a href="qlabel-h.html">qlabel.h</a>>#include <<a href="qbitmap-h.html">qbitmap.h</a>>#include <<a href="qapplication-h.html">qapplication.h</a>>#include <<a href="qlayout-h.html">qlayout.h</a>>#include <<a href="qcursor-h.html">qcursor.h</a>>// cb_bits and cm_bits were generated by X bitmap program.#define cb_width 32#define cb_height 32static unsigned char cb_bits[] = { // cursor bitmap 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0x06, 0x30, 0x00, 0x80, 0x01, 0xc0, 0x00, 0x40, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x04, 0x08, 0x3e, 0x3e, 0x08, 0x08, 0x03, 0xe0, 0x08, 0xc4, 0x00, 0x00, 0x11, 0x04, 0x1e, 0x78, 0x10, 0x02, 0x0c, 0x30, 0x20, 0x02, 0x40, 0x00, 0x20, 0x02, 0x40, 0x00, 0x20, 0x02, 0x40, 0x00, 0x20, 0x02, 0x20, 0x04, 0x20, 0x02, 0x20, 0x04, 0x20, 0x02, 0x10, 0x08, 0x20, 0x02, 0x08, 0x08, 0x20, 0x02, 0xf0, 0x07, 0x20, 0x04, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x10, 0x08, 0x00, 0xc0, 0x08, 0x08, 0x3c, 0x30, 0x08, 0x10, 0xe6, 0x19, 0x04, 0x20, 0x00, 0x0f, 0x02, 0x40, 0x00, 0x00, 0x01, 0x80, 0x01, 0xc0, 0x00, 0x00, 0x06, 0x30, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00};#define cm_width 32#define cm_height 32static unsigned char cm_bits[] = { // cursor bitmap mask 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xfe, 0x3f, 0x00, 0x80, 0x07, 0xf0, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0x60, 0x00, 0x00, 0x03, 0x30, 0x00, 0x00, 0x06, 0x18, 0x00, 0x00, 0x0c, 0x0c, 0x3e, 0x3e, 0x18, 0x0e, 0x03, 0xe0, 0x18, 0xc6, 0x00, 0x00, 0x31, 0x07, 0x1e, 0x78, 0x30, 0x03, 0x0c, 0x30, 0x60, 0x03, 0x40, 0x00, 0x60, 0x03, 0x40, 0x00, 0x60, 0x03, 0x40, 0x00, 0x60, 0x03, 0x20, 0x04, 0x60, 0x03, 0x20, 0x04, 0x60, 0x03, 0x10, 0x08, 0x60, 0x03, 0x08, 0x08, 0x60, 0x03, 0xf0, 0x07, 0x60, 0x06, 0x00, 0x00, 0x30, 0x06, 0x00, 0x00, 0x30, 0x0c, 0x00, 0xc0, 0x18, 0x0c, 0x3c, 0x30, 0x18, 0x18, 0xe6, 0x19, 0x0c, 0x30, 0x00, 0x0f, 0x06, 0x60, 0x00, 0x00, 0x03, 0xc0, 0x01, 0xc0, 0x01, 0x80, 0x07, 0xf0, 0x00, 0x00, 0xfe, 0x3f, 0x00, 0x00, 0xf8, 0x0f, 0x00};//// The CursorView contains many labels with different cursors.//class CursorView : public <a href="qwidget.html">QWidget</a> // cursor view{public: CursorView();};//// Constructs a cursor view.//CursorView::CursorView() // construct view{ struct List { CursorShape shape; const char* name; // cursor name }; static List list[] = { { ArrowCursor, "arrowCursor" }, { UpArrowCursor, "upArrowCursor" }, { CrossCursor, "crossCursor" }, { WaitCursor, "waitCursor" }, { IbeamCursor, "ibeamCursor" }, { SizeVerCursor, "sizeVerCursor" }, { SizeHorCursor, "sizeHorCursor" }, { SizeBDiagCursor, "sizeBDiagCursor" }, { SizeFDiagCursor, "sizeFDiagCursor" }, { SizeAllCursor, "sizeAllCursor" }, { BlankCursor, "blankCursor" }, { SplitVCursor, "splitVCursor" }, { SplitHCursor, "splitHCursor" }, { PointingHandCursor, "pointingHandCursor" }, { ForbiddenCursor, "forbiddenCursor" }, { WhatsThisCursor, "whatsThisCursor" } }; setCaption( "CursorView" ); // set window caption <a href="qgridlayout.html">QGridLayout</a>* grid = new <a href="qgridlayout.html">QGridLayout</a>( this, 5, 4, 20 ); <a href="qlabel.html">QLabel</a> *label; int i=0; for ( int y=0; y<4; y++ ) { // create the small labels for ( int x=0; x<4; x++ ) { label = new <a href="qlabel.html">QLabel</a>( this );<a name="x920"></a> label-><a href="qwidget.html#setCursor">setCursor</a>( QCursor( list[i].shape ) );<a name="x918"></a> label-><a href="qlabel.html#setText">setText</a>( list[i].name );<a name="x917"></a> label-><a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter );<a name="x914"></a> label-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Box | QFrame::Raised ); grid-><a href="qgridlayout.html#addWidget">addWidget</a>( label, x, y ); i++; } } <a href="qbitmap.html">QBitmap</a> cb( cb_width, cb_height, cb_bits, TRUE ); <a href="qbitmap.html">QBitmap</a> cm( cm_width, cm_height, cm_bits, TRUE ); <a href="qcursor.html">QCursor</a> custom( cb, cm ); // create bitmap cursor label = new <a href="qlabel.html">QLabel</a>( this ); // create the big label label-><a href="qwidget.html#setCursor">setCursor</a>( custom ); label-><a href="qlabel.html#setText">setText</a>( "Custom bitmap cursor" ); label-><a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter ); label-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Box | QFrame::Sunken );<a name="x915"></a> grid-><a href="qgridlayout.html#addMultiCellWidget">addMultiCellWidget</a>( label, 4, 4, 0, 3 );}//// Create and display a CursorView.//int main( int argc, char **argv ){ <a href="qapplication.html">QApplication</a> a( argc, argv ); // application object CursorView v; // cursor view a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &v ); v.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Cursors"); v.<a href="qwidget.html#show">show</a>(); return a.<a href="qapplication.html#exec">exec</a>();}</pre><p> <p>See also <a href="examples.html">Examples</a>.<!-- eof --><p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?