summaryrefslogtreecommitdiffstats
path: root/doc/html/cursor-example.html
blob: c119ecc1d887e43e4470677234104e22b5b218e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/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"><!--
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&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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.3.8   edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include &lt;<a href="tqlabel-h.html">tqlabel.h</a>&gt;
#include &lt;<a href="tqbitmap-h.html">tqbitmap.h</a>&gt;
#include &lt;<a href="qapplication-h.html">ntqapplication.h</a>&gt;
#include &lt;<a href="qlayout-h.html">ntqlayout.h</a>&gt;
#include &lt;<a href="qcursor-h.html">ntqcursor.h</a>&gt;

// cb_bits and cm_bits were generated by X bitmap program.

#define cb_width  32
#define cb_height 32

static 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 32

static 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="tqwidget.html">TQWidget</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" },
        { BusyCursor,           "busyCursor" }
    };

    setCaption( "CursorView" );                 // set window caption

    <a href="tqgridlayout.html">TQGridLayout</a>* grid = new <a href="tqgridlayout.html">TQGridLayout</a>( this, 5, 4, 20 );
    <a href="tqlabel.html">TQLabel</a> *label;

    int i=0;
    for ( int y=0; y&lt;4; y++ ) {                 // create the small labels
        for ( int x=0; x&lt;4; x++ ) {
            label = new <a href="tqlabel.html">TQLabel</a>( this );
<a name="x1121"></a>            label-&gt;<a href="tqwidget.html#setCursor">setCursor</a>( TQCursor( list[i].shape ) );
<a name="x1119"></a>            label-&gt;<a href="tqlabel.html#setText">setText</a>( list[i].name );
<a name="x1118"></a>            label-&gt;<a href="tqlabel.html#setAlignment">setAlignment</a>( AlignCenter );
<a name="x1115"></a>            label-&gt;<a href="tqframe.html#setMargin">setMargin</a>( 10 );
<a name="x1114"></a>            label-&gt;<a href="tqframe.html#setFrameStyle">setFrameStyle</a>( TQFrame::Box | TQFrame::Raised );
            grid-&gt;<a href="tqgridlayout.html#addWidget">addWidget</a>( label, x, y );
            i++;
        }
    }


    label = new <a href="tqlabel.html">TQLabel</a>( this );
    label-&gt;<a href="tqwidget.html#setCursor">setCursor</a>( TQCursor( list[i].shape ) );
    label-&gt;<a href="tqlabel.html#setText">setText</a>( list[i].name );
    label-&gt;<a href="tqlabel.html#setAlignment">setAlignment</a>( AlignCenter );
    label-&gt;<a href="tqframe.html#setMargin">setMargin</a>( 10 );
    label-&gt;<a href="tqframe.html#setFrameStyle">setFrameStyle</a>( TQFrame::Box | TQFrame::Raised );
    grid-&gt;<a href="tqgridlayout.html#addWidget">addWidget</a>( label, 4, 0 );



    <a href="tqbitmap.html">TQBitmap</a> cb( cb_width, cb_height, cb_bits, TRUE );
    <a href="tqbitmap.html">TQBitmap</a> cm( cm_width, cm_height, cm_bits, TRUE );
    <a href="ntqcursor.html">TQCursor</a> custom( cb, cm );                   // create bitmap cursor

    label = new <a href="tqlabel.html">TQLabel</a>( this );                 // create the big label
    label-&gt;<a href="tqwidget.html#setCursor">setCursor</a>( custom );
    label-&gt;<a href="tqlabel.html#setText">setText</a>( "Custom bitmap cursor" );
    label-&gt;<a href="tqlabel.html#setAlignment">setAlignment</a>( AlignCenter );
    label-&gt;<a href="tqframe.html#setMargin">setMargin</a>( 10 );
    label-&gt;<a href="tqframe.html#setFrameStyle">setFrameStyle</a>( TQFrame::Box | TQFrame::Sunken );
<a name="x1116"></a>    grid-&gt;<a href="tqgridlayout.html#addMultiCellWidget">addMultiCellWidget</a>( label, 4, 4, 1, 3 );

}


//
// Create and display a CursorView.
//

int main( int argc, char **argv )
{
    <a href="ntqapplication.html">TQApplication</a> a( argc, argv );               // application object
    CursorView   v;                             // cursor view
    a.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( &amp;v );
    v.<a href="tqwidget.html#setCaption">setCaption</a>("TQt Example - Cursors");
    v.<a href="tqwidget.html#show">show</a>();
    return a.<a href="ntqapplication.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 &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>