source: trunk/doc/html/qaxserver-example-multiple.html@ 203

Last change on this file since 203 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 8.5 KB
Line 
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/extensions/activeqt/examples/multiple/multiple.doc:44 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>Two simple Qt widgets (in-process)</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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>Two simple Qt widgets (in-process)</h1>
33
34
35
36The ActiveX controls in this example are simple <a href="qwidget.html">QWidget</a>
37subclasses reimplementing the paintEvent() method. The classes use
38the Q_CLASSINFO macro to
39<p> The example demonstrates the use of the Q_CLASSINFO macro to set
40<a href="activeqt.html#ActiveQt">ActiveQt</a>-specific attributes for <a href="qobject.html">QObject</a> sub classes, and the use of
41the <a href="qaxfactory.html#QAXFACTORY_BEGIN">QAXFACTORY_BEGIN</a>, <a href="qaxfactory.html#QAXCLASS">QAXCLASS</a> and <a href="qaxfactory.html#QAXFACTORY_END">QAXFACTORY_END</a> macros.
42<p>
43
44<pre> class QAxWidget1 : public <a href="qwidget.html">QWidget</a>
45 {
46 <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
47 Q_CLASSINFO("ClassID", "{1D9928BD-4453-4bdd-903D-E525ED17FDE5}")
48 Q_CLASSINFO("InterfaceID", "{99F6860E-2C5A-42ec-87F2-43396F4BE389}")
49 Q_CLASSINFO("EventsID", "{0A3E9F27-E4F1-45bb-9E47-63099BCCD0E3}")
50</pre>The class declaration includes the Q_OBJECT macro to activate Qt's <a href="metaobjects.html#meta-object">meta object</a> system, and sets COM identifiers for the class using the
51Q_CLASSINFO macro.
52<pre> Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
53 public:
54 QAxWidget1( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0, WFlags f = 0 )
55 : <a href="qwidget.html">QWidget</a>( parent, name, f ), fill_color( red )
56 {
57 }
58
59 <a href="qcolor.html">QColor</a> fillColor() const
60 {
61 return fill_color;
62 }
63 void setFillColor( const <a href="qcolor.html">QColor</a> &amp;fc )
64 {
65 fill_color = fc;
66 repaint();
67 }
68
69 protected:
70 void paintEvent( <a href="qpaintevent.html">QPaintEvent</a> *e )
71 {
72 <a href="qpainter.html">QPainter</a> paint( this );
73 <a href="qrect.html">QRect</a> r = rect();
74 <a name="x2544"></a> r.<a href="qrect.html#addCoords">addCoords</a>( 10, 10, -10, -10 );
75 <a name="x2543"></a> paint.<a href="qpainter.html#fillRect">fillRect</a>( r, fill_color );
76 }
77
78 private:
79 <a href="qcolor.html">QColor</a> fill_color;
80 };
81</pre>The control draws a filled rectangle. The fill color is exposed as a
82property using the Q_PROPERTY macro.
83<p>
84
85<pre> class QAxWidget2 : public <a href="qwidget.html">QWidget</a>
86 {
87 Q_OBJECT
88 Q_CLASSINFO("ClassID", "{58139D56-6BE9-4b17-937D-1B1EDEDD5B71}")
89 Q_CLASSINFO("InterfaceID", "{B66280AB-08CC-4dcc-924F-58E6D7975B7D}")
90 Q_CLASSINFO("EventsID", "{D72BACBA-03C4-4480-B4BB-DE4FE3AA14A0}")
91 Q_CLASSINFO("ToSuperClass", "QAxWidget2")
92 Q_CLASSINFO("StockEvents", "yes")
93</pre>The declaration of the second control class uses the Q_CLASSINFO macro
94to set the COM identifiers as well as additional COM attributes for the
95class. Objects of that class will not expose the <a href="qwidget.html">QWidget</a> API, and provide
96the ActiveX stock events (ie. Click, KeyDown etc.).
97<pre> Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth )
98 public:
99 QAxWidget2( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0, WFlags f = 0 )
100 : <a href="qwidget.html">QWidget</a>( parent, name, f ), line_width( 1 )
101 {
102 }
103
104 int lineWidth() const
105 {
106 return line_width;
107 }
108 void setLineWidth( int lw )
109 {
110 line_width = lw;
111 repaint();
112 }
113
114 protected:
115 void paintEvent( <a href="qpaintevent.html">QPaintEvent</a> *e )
116 {
117 <a href="qpainter.html">QPainter</a> paint( this );
118 <a name="x2546"></a> <a href="qpen.html">QPen</a> pen = paint.<a href="qpainter.html#pen">pen</a>();
119 <a name="x2548"></a> pen.<a href="qpen.html#setWidth">setWidth</a>( line_width );
120 <a name="x2547"></a> paint.<a href="qpainter.html#setPen">setPen</a>( pen );
121
122 <a href="qrect.html">QRect</a> r = rect();
123 <a name="x2549"></a> r.<a href="qrect.html#addCoords">addCoords</a>( 10, 10, -10, -10 );
124 <a name="x2545"></a> paint.<a href="qpainter.html#drawEllipse">drawEllipse</a>( r );
125 }
126
127 private:
128 int line_width;
129 };
130</pre>The control draws a circle. The line width is exposed as a property
131using the Q_PROPERTY macro.
132<p> The controls are exposed by the implementation of <a href="qaxfactory.html">QAxFactory</a> as provided
133by the QAXFACTORY_BEGIN and QAXFACTORY_END macros.
134
135
136<pre> #include &lt;<a href="qaxfactory-h.html">qaxfactory.h</a>&gt;
137
138 #include "ax1.h"
139 #include "ax2.h"
140
141 QAXFACTORY_BEGIN("{98DE28B6-6CD3-4e08-B9FA-3D1DB43F1D2F}", "{05828915-AD1C-47ab-AB96-D6AD1E25F0E2}")
142</pre>The factory is initialied using the QAXFACTORY_BEGIN macro, providing
143the IDs for the application and the type library.
144<pre> QAXCLASS(QAxWidget1)
145 QAXCLASS(QAxWidget2)
146</pre>The classes exposed are listed using the QAXCLASS macro.
147<pre> QAXFACTORY_END()
148</pre>Finally the factory declaration is closed using the QAXFACTORY_END
149macro.
150<p> To build the example you must first build the <a href="qaxserver.html">QAxServer</a> library. Then run qmake and your make tool in
151<tt>examples/multiple</tt>.
152<p> <hr>
153<p> The <a href="qaxserver-demo-multiple.html">demonstration</a> requires your
154WebBrowser to support ActiveX controls, and scripting to be enabled.
155<p>
156
157<pre> &lt;script language=javascript&gt;
158 function setColor( form )
159 {
160 Ax1.fillColor = form.colorEdit.value;
161 }
162
163 function setWidth( form )
164 {
165 Ax2.lineWidth = form.widthEdit.value;
166 }
167 &lt;/script&gt;
168
169 &lt;p&gt;
170 This is one QWidget subclass:&lt;br&gt;
171 &lt;object ID="Ax1" CLASSID="CLSID:1D9928BD-4453-4bdd-903D-E525ED17FDE5"
172 CODEBASE=http://www.trolltech.com/demos/multipleax.cab&gt;
173 [Object not available! Did you forget to build and register the server?]
174 &lt;/object&gt;&lt;br&gt;
175 &lt;form&gt;
176 Fill Color: &lt;input type="edit" ID="colorEdit" value = "red"&gt;
177 &lt;input type="button" value = "Set" onClick="setColor(this.form)"&gt;
178 &lt;input type="button" value = "Hide" onClick="Ax1.hide()"&gt;
179 &lt;input type="button" value = "Show" onClick="Ax1.show()"&gt;
180 &lt;/form&gt;
181
182 &lt;p&gt;
183 This is another QWidget subclass:&lt;br&gt;
184 &lt;object ID="Ax2" CLASSID="CLSID:58139D56-6BE9-4b17-937D-1B1EDEDD5B71"
185 CODEBASE=http://www.trolltech.com/demos/multipleax.cab&gt;
186 [Object not available! Did you forget to build and register the server?]
187 &lt;/object&gt;&lt;br&gt;
188 &lt;form&gt;
189 Line width: &lt;input type="edit" ID="widthEdit" value = "1"&gt;
190 &lt;input type="button" value = "Set" onClick="setWidth(this.form)"&gt;
191 &lt;/form&gt;
192</pre><p>See also <a href="qaxserver-examples.html">The QAxServer Examples</a>.
193
194<!-- eof -->
195<p><address><hr><div align=center>
196<table width=100% cellspacing=0 border=0><tr>
197<td>Copyright &copy; 2007
198<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
199<td align=right><div align=right>Qt 3.3.8</div>
200</table></div></address></body>
201</html>
Note: See TracBrowser for help on using the repository browser.