1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/cursor/cursor.doc:4 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Cursors</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <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>
|
---|
33 |
|
---|
34 |
|
---|
35 | <p>
|
---|
36 | This example shows how to set a mouse cursor for a widget.
|
---|
37 | <p> <hr>
|
---|
38 | <p> Implementation:
|
---|
39 | <p> <pre>/****************************************************************************
|
---|
40 | ** $Id: cursor-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
41 | **
|
---|
42 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
43 | **
|
---|
44 | ** This file is part of an example program for Qt. This example
|
---|
45 | ** program may be used, distributed and modified without limitation.
|
---|
46 | **
|
---|
47 | *****************************************************************************/
|
---|
48 |
|
---|
49 | #include <<a href="qlabel-h.html">qlabel.h</a>>
|
---|
50 | #include <<a href="qbitmap-h.html">qbitmap.h</a>>
|
---|
51 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
52 | #include <<a href="qlayout-h.html">qlayout.h</a>>
|
---|
53 | #include <<a href="qcursor-h.html">qcursor.h</a>>
|
---|
54 |
|
---|
55 | // cb_bits and cm_bits were generated by X bitmap program.
|
---|
56 |
|
---|
57 | #define cb_width 32
|
---|
58 | #define cb_height 32
|
---|
59 |
|
---|
60 | static unsigned char cb_bits[] = { // cursor bitmap
|
---|
61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00,
|
---|
62 | 0x00, 0x06, 0x30, 0x00, 0x80, 0x01, 0xc0, 0x00, 0x40, 0x00, 0x00, 0x01,
|
---|
63 | 0x20, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x04, 0x08, 0x3e, 0x3e, 0x08,
|
---|
64 | 0x08, 0x03, 0xe0, 0x08, 0xc4, 0x00, 0x00, 0x11, 0x04, 0x1e, 0x78, 0x10,
|
---|
65 | 0x02, 0x0c, 0x30, 0x20, 0x02, 0x40, 0x00, 0x20, 0x02, 0x40, 0x00, 0x20,
|
---|
66 | 0x02, 0x40, 0x00, 0x20, 0x02, 0x20, 0x04, 0x20, 0x02, 0x20, 0x04, 0x20,
|
---|
67 | 0x02, 0x10, 0x08, 0x20, 0x02, 0x08, 0x08, 0x20, 0x02, 0xf0, 0x07, 0x20,
|
---|
68 | 0x04, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x10, 0x08, 0x00, 0xc0, 0x08,
|
---|
69 | 0x08, 0x3c, 0x30, 0x08, 0x10, 0xe6, 0x19, 0x04, 0x20, 0x00, 0x0f, 0x02,
|
---|
70 | 0x40, 0x00, 0x00, 0x01, 0x80, 0x01, 0xc0, 0x00, 0x00, 0x06, 0x30, 0x00,
|
---|
71 | 0x00, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00};
|
---|
72 |
|
---|
73 | #define cm_width 32
|
---|
74 | #define cm_height 32
|
---|
75 |
|
---|
76 | static unsigned char cm_bits[] = { // cursor bitmap mask
|
---|
77 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xfe, 0x3f, 0x00,
|
---|
78 | 0x80, 0x07, 0xf0, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0x60, 0x00, 0x00, 0x03,
|
---|
79 | 0x30, 0x00, 0x00, 0x06, 0x18, 0x00, 0x00, 0x0c, 0x0c, 0x3e, 0x3e, 0x18,
|
---|
80 | 0x0e, 0x03, 0xe0, 0x18, 0xc6, 0x00, 0x00, 0x31, 0x07, 0x1e, 0x78, 0x30,
|
---|
81 | 0x03, 0x0c, 0x30, 0x60, 0x03, 0x40, 0x00, 0x60, 0x03, 0x40, 0x00, 0x60,
|
---|
82 | 0x03, 0x40, 0x00, 0x60, 0x03, 0x20, 0x04, 0x60, 0x03, 0x20, 0x04, 0x60,
|
---|
83 | 0x03, 0x10, 0x08, 0x60, 0x03, 0x08, 0x08, 0x60, 0x03, 0xf0, 0x07, 0x60,
|
---|
84 | 0x06, 0x00, 0x00, 0x30, 0x06, 0x00, 0x00, 0x30, 0x0c, 0x00, 0xc0, 0x18,
|
---|
85 | 0x0c, 0x3c, 0x30, 0x18, 0x18, 0xe6, 0x19, 0x0c, 0x30, 0x00, 0x0f, 0x06,
|
---|
86 | 0x60, 0x00, 0x00, 0x03, 0xc0, 0x01, 0xc0, 0x01, 0x80, 0x07, 0xf0, 0x00,
|
---|
87 | 0x00, 0xfe, 0x3f, 0x00, 0x00, 0xf8, 0x0f, 0x00};
|
---|
88 |
|
---|
89 |
|
---|
90 | //
|
---|
91 | // The CursorView contains many labels with different cursors.
|
---|
92 | //
|
---|
93 |
|
---|
94 | class CursorView : public <a href="qwidget.html">QWidget</a> // cursor view
|
---|
95 | {
|
---|
96 | public:
|
---|
97 | CursorView();
|
---|
98 | };
|
---|
99 |
|
---|
100 | //
|
---|
101 | // Constructs a cursor view.
|
---|
102 | //
|
---|
103 |
|
---|
104 | CursorView::CursorView() // construct view
|
---|
105 | {
|
---|
106 | struct List {
|
---|
107 | CursorShape shape;
|
---|
108 | const char* name; // cursor name
|
---|
109 | };
|
---|
110 | static List list[] = {
|
---|
111 | { ArrowCursor, "arrowCursor" },
|
---|
112 | { UpArrowCursor, "upArrowCursor" },
|
---|
113 | { CrossCursor, "crossCursor" },
|
---|
114 | { WaitCursor, "waitCursor" },
|
---|
115 | { IbeamCursor, "ibeamCursor" },
|
---|
116 | { SizeVerCursor, "sizeVerCursor" },
|
---|
117 | { SizeHorCursor, "sizeHorCursor" },
|
---|
118 | { SizeBDiagCursor, "sizeBDiagCursor" },
|
---|
119 | { SizeFDiagCursor, "sizeFDiagCursor" },
|
---|
120 | { SizeAllCursor, "sizeAllCursor" },
|
---|
121 | { BlankCursor, "blankCursor" },
|
---|
122 | { SplitVCursor, "splitVCursor" },
|
---|
123 | { SplitHCursor, "splitHCursor" },
|
---|
124 | { PointingHandCursor, "pointingHandCursor" },
|
---|
125 | { ForbiddenCursor, "forbiddenCursor" },
|
---|
126 | { WhatsThisCursor, "whatsThisCursor" },
|
---|
127 | { BusyCursor, "busyCursor" }
|
---|
128 | };
|
---|
129 |
|
---|
130 | setCaption( "CursorView" ); // set window caption
|
---|
131 |
|
---|
132 | <a href="qgridlayout.html">QGridLayout</a>* grid = new <a href="qgridlayout.html">QGridLayout</a>( this, 5, 4, 20 );
|
---|
133 | <a href="qlabel.html">QLabel</a> *label;
|
---|
134 |
|
---|
135 | int i=0;
|
---|
136 | for ( int y=0; y<4; y++ ) { // create the small labels
|
---|
137 | for ( int x=0; x<4; x++ ) {
|
---|
138 | label = new <a href="qlabel.html">QLabel</a>( this );
|
---|
139 | <a name="x1121"></a> label-><a href="qwidget.html#setCursor">setCursor</a>( QCursor( list[i].shape ) );
|
---|
140 | <a name="x1119"></a> label-><a href="qlabel.html#setText">setText</a>( list[i].name );
|
---|
141 | <a name="x1118"></a> label-><a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter );
|
---|
142 | <a name="x1115"></a> label-><a href="qframe.html#setMargin">setMargin</a>( 10 );
|
---|
143 | <a name="x1114"></a> label-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Box | QFrame::Raised );
|
---|
144 | grid-><a href="qgridlayout.html#addWidget">addWidget</a>( label, x, y );
|
---|
145 | i++;
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | label = new <a href="qlabel.html">QLabel</a>( this );
|
---|
151 | label-><a href="qwidget.html#setCursor">setCursor</a>( QCursor( list[i].shape ) );
|
---|
152 | label-><a href="qlabel.html#setText">setText</a>( list[i].name );
|
---|
153 | label-><a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter );
|
---|
154 | label-><a href="qframe.html#setMargin">setMargin</a>( 10 );
|
---|
155 | label-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Box | QFrame::Raised );
|
---|
156 | grid-><a href="qgridlayout.html#addWidget">addWidget</a>( label, 4, 0 );
|
---|
157 |
|
---|
158 |
|
---|
159 |
|
---|
160 | <a href="qbitmap.html">QBitmap</a> cb( cb_width, cb_height, cb_bits, TRUE );
|
---|
161 | <a href="qbitmap.html">QBitmap</a> cm( cm_width, cm_height, cm_bits, TRUE );
|
---|
162 | <a href="qcursor.html">QCursor</a> custom( cb, cm ); // create bitmap cursor
|
---|
163 |
|
---|
164 | label = new <a href="qlabel.html">QLabel</a>( this ); // create the big label
|
---|
165 | label-><a href="qwidget.html#setCursor">setCursor</a>( custom );
|
---|
166 | label-><a href="qlabel.html#setText">setText</a>( "Custom bitmap cursor" );
|
---|
167 | label-><a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter );
|
---|
168 | label-><a href="qframe.html#setMargin">setMargin</a>( 10 );
|
---|
169 | label-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Box | QFrame::Sunken );
|
---|
170 | <a name="x1116"></a> grid-><a href="qgridlayout.html#addMultiCellWidget">addMultiCellWidget</a>( label, 4, 4, 1, 3 );
|
---|
171 |
|
---|
172 | }
|
---|
173 |
|
---|
174 |
|
---|
175 | //
|
---|
176 | // Create and display a CursorView.
|
---|
177 | //
|
---|
178 |
|
---|
179 | int main( int argc, char **argv )
|
---|
180 | {
|
---|
181 | <a href="qapplication.html">QApplication</a> a( argc, argv ); // application object
|
---|
182 | CursorView v; // cursor view
|
---|
183 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &v );
|
---|
184 | v.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Cursors");
|
---|
185 | v.<a href="qwidget.html#show">show</a>();
|
---|
186 | return a.<a href="qapplication.html#exec">exec</a>();
|
---|
187 | }
|
---|
188 | </pre>
|
---|
189 |
|
---|
190 | <p> <p>See also <a href="examples.html">Examples</a>.
|
---|
191 |
|
---|
192 | <!-- eof -->
|
---|
193 | <p><address><hr><div align=center>
|
---|
194 | <table width=100% cellspacing=0 border=0><tr>
|
---|
195 | <td>Copyright © 2007
|
---|
196 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
197 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
198 | </table></div></address></body>
|
---|
199 | </html>
|
---|