📄 cursor-cursor-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 - cursor/cursor.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>Cursors</h1><br clear="all"> This example shows how to set a mouse cursor for a widget. <hr> Implementation:<pre>/****************************************************************************** $Id: qt/examples/cursor/cursor.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="qlabel.h"></a><a href="qlabel-h.html">qlabel.h</a>>#include <<a name="qbitmap.h"></a><a href="qbitmap-h.html">qbitmap.h</a>>#include <<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>>#include <<a name="qlayout.h"></a><a href="qlayout-h.html">qlayout.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 QWidget // cursor view{public: CursorView();};//// Constructs a cursor view.//CursorView::CursorView() // construct view{ static struct { QCursorShape shape; const char* name; // cursor name } 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" }, { BitmapCursor, "" } // sentinel }; setCaption( "CursorView" ); // set window caption <a name="QGridLayout"></a><a href="qgridlayout.html">QGridLayout</a>* grid = new <a href="qgridlayout.html">QGridLayout</a>( this, 5, 4, 20 ); <a name="QLabel"></a><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++ ) { if ( list[i].shape == BitmapCursor ) break; label = new <a href="qlabel.html">QLabel</a>( this ); label-><a name="setCursor"></a><a href="qwidget.html#9b6e22">setCursor</a>( <a name="QCursor"></a><a href="qcursor.html">QCursor</a>( list[i].shape ) ); label-><a name="setText"></a><a href="qlabel.html#bc5ea6">setText</a>( list[i].name ); label-><a name="setAlignment"></a><a href="qlabel.html#4743c8">setAlignment</a>( AlignCenter ); label-><a name="setFrameStyle"></a><a href="qframe.html#558f79">setFrameStyle</a>( QFrame::Box | QFrame::Raised ); grid-><a name="addWidget"></a><a href="qgridlayout.html#dac29c">addWidget</a>( label, x, y ); i++; } } <a name="QBitmap"></a><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#9b6e22">setCursor</a>( custom ); label-><a href="qlabel.html#bc5ea6">setText</a>( "Custom bitmap cursor" ); label-><a href="qlabel.html#4743c8">setAlignment</a>( AlignCenter ); label-><a href="qframe.html#558f79">setFrameStyle</a>( QFrame::Box | QFrame::Sunken ); grid-><a name="addMultiCellWidget"></a><a href="qgridlayout.html#92faca">addMultiCellWidget</a>( label, 4, 4, 0, 3 );}//// Create and display a CursorView.//int main( int argc, char **argv ){ <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv ); // application object CursorView v; // cursor view a.<a name="setMainWidget"></a><a href="qapplication.html#7ad759">setMainWidget</a>( &v ); v.<a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>("Qt Example - Cursors"); v.<a name="show"></a><a href="qwidget.html#200ee5">show</a>(); return a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();}</pre><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -