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"><!--
|
---|
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>Two simple Qt widgets (in-process)</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | The ActiveX controls in this example are simple <a href="qwidget.html">QWidget</a>
|
---|
37 | subclasses reimplementing the paintEvent() method. The classes use
|
---|
38 | the 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
|
---|
41 | the <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
|
---|
51 | Q_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> &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
|
---|
82 | property 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
|
---|
94 | to set the COM identifiers as well as additional COM attributes for the
|
---|
95 | class. Objects of that class will not expose the <a href="qwidget.html">QWidget</a> API, and provide
|
---|
96 | the 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
|
---|
131 | using the Q_PROPERTY macro.
|
---|
132 | <p> The controls are exposed by the implementation of <a href="qaxfactory.html">QAxFactory</a> as provided
|
---|
133 | by the QAXFACTORY_BEGIN and QAXFACTORY_END macros.
|
---|
134 |
|
---|
135 |
|
---|
136 | <pre> #include <<a href="qaxfactory-h.html">qaxfactory.h</a>>
|
---|
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
|
---|
143 | the 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
|
---|
149 | macro.
|
---|
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
|
---|
154 | WebBrowser to support ActiveX controls, and scripting to be enabled.
|
---|
155 | <p>
|
---|
156 |
|
---|
157 | <pre> <script language=javascript>
|
---|
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 | </script>
|
---|
168 |
|
---|
169 | <p>
|
---|
170 | This is one QWidget subclass:<br>
|
---|
171 | <object ID="Ax1" CLASSID="CLSID:1D9928BD-4453-4bdd-903D-E525ED17FDE5"
|
---|
172 | CODEBASE=http://www.trolltech.com/demos/multipleax.cab>
|
---|
173 | [Object not available! Did you forget to build and register the server?]
|
---|
174 | </object><br>
|
---|
175 | <form>
|
---|
176 | Fill Color: <input type="edit" ID="colorEdit" value = "red">
|
---|
177 | <input type="button" value = "Set" onClick="setColor(this.form)">
|
---|
178 | <input type="button" value = "Hide" onClick="Ax1.hide()">
|
---|
179 | <input type="button" value = "Show" onClick="Ax1.show()">
|
---|
180 | </form>
|
---|
181 |
|
---|
182 | <p>
|
---|
183 | This is another QWidget subclass:<br>
|
---|
184 | <object ID="Ax2" CLASSID="CLSID:58139D56-6BE9-4b17-937D-1B1EDEDD5B71"
|
---|
185 | CODEBASE=http://www.trolltech.com/demos/multipleax.cab>
|
---|
186 | [Object not available! Did you forget to build and register the server?]
|
---|
187 | </object><br>
|
---|
188 | <form>
|
---|
189 | Line width: <input type="edit" ID="widthEdit" value = "1">
|
---|
190 | <input type="button" value = "Set" onClick="setWidth(this.form)">
|
---|
191 | </form>
|
---|
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 © 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>
|
---|