You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qt3/doc/html/cursor-example.html

200 lines
8.5 KiB

<!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 Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include &lt;<a href="qlabel-h.html">qlabel.h</a>&gt;
#include &lt;<a href="qbitmap-h.html">qbitmap.h</a>&gt;
#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
#include &lt;<a href="qlayout-h.html">qlayout.h</a>&gt;
#include &lt;<a href="qcursor-h.html">qcursor.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="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" },
{ BusyCursor, "busyCursor" }
};
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&lt;4; y++ ) { // create the small labels
for ( int x=0; x&lt;4; x++ ) {
label = new <a href="qlabel.html">QLabel</a>( this );
<a name="x1121"></a> label-&gt;<a href="qwidget.html#setCursor">setCursor</a>( QCursor( list[i].shape ) );
<a name="x1119"></a> label-&gt;<a href="qlabel.html#setText">setText</a>( list[i].name );
<a name="x1118"></a> label-&gt;<a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter );
<a name="x1115"></a> label-&gt;<a href="qframe.html#setMargin">setMargin</a>( 10 );
<a name="x1114"></a> label-&gt;<a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Box | QFrame::Raised );
grid-&gt;<a href="qgridlayout.html#addWidget">addWidget</a>( label, x, y );
i++;
}
}
label = new <a href="qlabel.html">QLabel</a>( this );
label-&gt;<a href="qwidget.html#setCursor">setCursor</a>( QCursor( list[i].shape ) );
label-&gt;<a href="qlabel.html#setText">setText</a>( list[i].name );
label-&gt;<a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter );
label-&gt;<a href="qframe.html#setMargin">setMargin</a>( 10 );
label-&gt;<a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Box | QFrame::Raised );
grid-&gt;<a href="qgridlayout.html#addWidget">addWidget</a>( label, 4, 0 );
<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-&gt;<a href="qwidget.html#setCursor">setCursor</a>( custom );
label-&gt;<a href="qlabel.html#setText">setText</a>( "Custom bitmap cursor" );
label-&gt;<a href="qlabel.html#setAlignment">setAlignment</a>( AlignCenter );
label-&gt;<a href="qframe.html#setMargin">setMargin</a>( 10 );
label-&gt;<a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Box | QFrame::Sunken );
<a name="x1116"></a> grid-&gt;<a href="qgridlayout.html#addMultiCellWidget">addMultiCellWidget</a>( label, 4, 4, 1, 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>( &amp;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 &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>