diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
commit | bd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch) | |
tree | 7a520322212d48ebcb9fbe1087e7fca28b76185c /doc/html/qaxserver-example-hierarchy.html | |
download | qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip |
Add Qt3 development HEAD version
Diffstat (limited to 'doc/html/qaxserver-example-hierarchy.html')
-rw-r--r-- | doc/html/qaxserver-example-hierarchy.html | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/doc/html/qaxserver-example-hierarchy.html b/doc/html/qaxserver-example-hierarchy.html new file mode 100644 index 0000000..0a67304 --- /dev/null +++ b/doc/html/qaxserver-example-hierarchy.html @@ -0,0 +1,262 @@ +<!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/extensions/activeqt/examples/hierarchy/hierarchy.doc:47 --> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title>Qt Widget Hierarchy (in-process)</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 Classes</font></a> + | <a href="mainclasses.html"> +<font color="#004faf">Main Classes</font></a> + | <a href="annotated.html"> +<font color="#004faf">Annotated</font></a> + | <a href="groups.html"> +<font color="#004faf">Grouped 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>Qt Widget Hierarchy (in-process)</h1> + + + +The ActiveX control in this example is a <a href="qwidget.html">QWidget</a> +subclass with child widgets that are accessible as sub types. +<p> + +<pre> class QParentWidget : public <a href="qwidget.html">QWidget</a> + { + <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a> + public: + QParentWidget( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0, WFlags f = 0 ); + + <a href="qsize.html">QSize</a> sizeHint() const; + + public slots: + void createSubWidget( const <a href="qstring.html">QString</a> &name ); + + QSubWidget *subWidget( const <a href="qstring.html">QString</a> &name ); + + private: + <a href="qvboxlayout.html">QVBoxLayout</a> *vbox; + }; +</pre>The <tt>QParentWidget</tt> class provides slots to create a widget +with a name, and to return a pointer to a named widget. +<p> + +<pre> QParentWidget::QParentWidget( <a href="qwidget.html">QWidget</a> *parent, const char *name, WFlags f ) + : <a href="qwidget.html">QWidget</a>( parent, name, f ) + { + vbox = new <a href="qvboxlayout.html">QVBoxLayout</a>( this ); + <a name="x2649"></a> vbox-><a href="qlayout.html#setAutoAdd">setAutoAdd</a>( TRUE ); + } +</pre>The constructor of QParentWidget creates a vertical box layout. +New child widgets are automatically added to the layout. +<p> <pre> void QParentWidget::createSubWidget( const <a href="qstring.html">QString</a> &name ) + { + QSubWidget *sw = new QSubWidget( this, name ); + sw->setLabel( name ); + sw-><a href="qwidget.html#show">show</a>(); + } +</pre>The <tt>createSubWidget</tt> slot creates a new <tt>QSubWidget</tt> with +the name provided in the parameter, and sets the label to that +name. The widget is also shown explicitly. +<p> <pre> QSubWidget *QParentWidget::subWidget( const <a href="qstring.html">QString</a> &name ) + { + return (QSubWidget*)<a href="qobject.html#child">child</a>( name, "QSubWidget" ); + } +</pre>The <tt>subWidget</tt> slot uses the <a href="qobject.html#child">QObject::child</a>() function and +returns the first child of type <tt>QSubWidget</tt> that has the requested +name. +<p> + +<pre> class QSubWidget : public <a href="qwidget.html">QWidget</a> + { + Q_OBJECT + Q_PROPERTY( QString label READ label WRITE setLabel ) + public: + QSubWidget( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0, WFlags f = 0 ); + + void setLabel( const <a href="qstring.html">QString</a> &text ); + <a href="qstring.html">QString</a> label() const; + + <a href="qsize.html">QSize</a> sizeHint() const; + + protected: + void paintEvent( <a href="qpaintevent.html">QPaintEvent</a> *e ); + + private: + <a href="qstring.html">QString</a> lbl; + }; +</pre>The <tt>QSubWidget</tt> class has a single string-property <tt>label</tt>, +and implements the paintEvent to draw the label. +<p> + +<pre> QSubWidget::QSubWidget( <a href="qwidget.html">QWidget</a> *parent, const char *name, WFlags f ) + : <a href="qwidget.html">QWidget</a>( parent, name, f ) + { + } + + void QSubWidget::setLabel( const <a href="qstring.html">QString</a> &text ) + { + lbl = text; + <a href="qobject.html#setName">setName</a>( text ); + <a href="qwidget.html#update">update</a>(); + } + + QString QSubWidget::label() const + { + return lbl; + } + + QSize QSubWidget::<a href="qwidget.html#sizeHint">sizeHint</a>() const + { + <a href="qfontmetrics.html">QFontMetrics</a> fm( <a href="qwidget.html#font">font</a>() ); + return QSize( fm.<a href="qfontmetrics.html#width">width</a>(lbl), fm.<a href="qfontmetrics.html#height">height</a>() ); + } + + void QSubWidget::<a href="qwidget.html#paintEvent">paintEvent</a>( <a href="qpaintevent.html">QPaintEvent</a> * ) + { + <a href="qpainter.html">QPainter</a> painter(this); + painter.<a href="qpainter.html#setPen">setPen</a>( <a href="qwidget.html#colorGroup">colorGroup</a>().text() ); + painter.<a href="qpainter.html#drawText">drawText</a>( <a href="qwidget.html#rect">rect</a>(), AlignCenter, lbl ); + } +</pre>The implementation of the QSubWidget class is self-explanatory. +<p> + +<pre> class ActiveQtFactory : public <a href="qaxfactory.html">QAxFactory</a> + { + public: + ActiveQtFactory( const <a href="quuid.html">QUuid</a> &lib, const <a href="quuid.html">QUuid</a> &app ) + : <a href="qaxfactory.html">QAxFactory</a>( lib, app ) + {} + <a href="qstringlist.html">QStringList</a> featureList() const + { + <a href="qstringlist.html">QStringList</a> list; + list << "QParentWidget"; + list << "QSubWidget"; + return list; + } +</pre>The <tt>ActiveQtFactory</tt> class implements a <a href="qaxfactory.html">QAxFactory</a>. It returns +the class names of all supported types, <tt>QParentWidget</tt> and +<tt>QSubWidget</tt>, from the <tt>featureList()</tt> reimplementation. +<p> <pre> <a href="qwidget.html">QWidget</a> *create( const <a href="qstring.html">QString</a> &key, QWidget *parent, const char *name ) + { + if ( key == "QParentWidget" ) + return new QParentWidget( parent, name ); + + return 0; + } +</pre>The factory can however only create objects of the <tt>QParentWidget</tt> +type directly - objects of subtypes can only be created through the +interface of <tt>QParentWidget</tt> objects. +<p> <pre> <a href="quuid.html">QUuid</a> classID( const <a href="qstring.html">QString</a> &key ) const + { + if ( key == "QParentWidget" ) + return QUuid( "{d574a747-8016-46db-a07c-b2b4854ee75c}" ); + if ( key == "QSubWidget" ) + return QUuid( "{850652f4-8f71-4f69-b745-bce241ccdc30}" ); + + return QUuid(); + } + <a href="quuid.html">QUuid</a> interfaceID( const <a href="qstring.html">QString</a> &key ) const + { + if ( key == "QParentWidget" ) + return QUuid( "{4a30719d-d9c2-4659-9d16-67378209f822}" ); + if ( key == "QSubWidget" ) + return QUuid( "{2d76cc2f-3488-417a-83d6-debff88b3c3f}" ); + + return QUuid(); + } + <a href="quuid.html">QUuid</a> eventsID( const <a href="qstring.html">QString</a> &key ) const + { + if ( key == "QParentWidget" ) + return QUuid( "{aac9f855-c3dc-4cae-b747-c77f4d509f4c}" ); + if ( key == "QSubWidget" ) + return QUuid( "{25fac47e-c723-4696-8c74-6185903bdf65}" ); + + return QUuid(); + } +</pre>COM however requires the IDs for the interfaces of the sub types as +well to be able to marshal calls correctly. +<p> <pre> <a href="qstring.html">QString</a> exposeToSuperClass( const <a href="qstring.html">QString</a> &key ) const + { + if ( key == "QSubWidget" ) + return key; + return QAxFactory::exposeToSuperClass(key); + } + }; +</pre>Objects of the <tt>QSubWidget</tt> type should not expose the full +functionality of e.g. <a href="qwidget.html">QWidget</a>. Only those properties and slots +explicitly declared in the type are accessible. +<p> <pre> QAXFACTORY_EXPORT( ActiveQtFactory, "{9e626211-be62-4d18-9483-9419358fbb03}", "{75c276de-1df5-451f-a004-e4fa1a587df1}" ) +</pre>The factory is then exported using the <a href="qaxfactory.html#QAXFACTORY_EXPORT">QAXFACTORY_EXPORT</a> +macro. +<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 +<tt>examples/multiple</tt>. +<p> <hr> +<p> The <a href="qaxserver-demo-hierarchy.html">demonstration</a> requires your +WebBrowser to support ActiveX controls, and scripting to be enabled. +<p> + +<pre> <script language=javascript> + function createSubWidget( form ) + { + ParentWidget.createSubWidget( form.nameEdit.value ); + } + + function renameSubWidget( form ) + { + var SubWidget = ParentWidget.subWidget( form.nameEdit.value ); + if ( !SubWidget ) { + alert( "No such widget " + form.nameEdit.value + "!" ); + return; + } + SubWidget.label = form.labelEdit.value; + form.nameEdit.value = SubWidget.label; + } + + function setFont( form ) + { + ParentWidget.font = form.fontEdit.value; + } + </script> + + <p> + This widget can have many children!<br> + <object ID="ParentWidget" CLASSID="CLSID:d574a747-8016-46db-a07c-b2b4854ee75c" + CODEBASE=http://www.trolltech.com/demos/hierarchy.cab> + [Object not available! Did you forget to build and register the server?] + </object><br> + <form> + <input type="edit" ID="nameEdit" value = "<enter object name>"> + <input type="button" value = "Create" onClick="createSubWidget(this.form)"> + <input type="edit" ID="labelEdit"> + <input type="button" value = "Rename" onClick="renameSubWidget(this.form)"> + <br> + <input type="edit" ID="fontEdit" value = "MS Sans Serif"> + <input type="button" value = "Set Font" onClick="setFont(this.form)"> + </form> +</pre><p>See also <a href="qaxserver-examples.html">The QAxServer Examples</a>. + +<!-- eof --> +<p><address><hr><div align=center> +<table width=100% cellspacing=0 border=0><tr> +<td>Copyright © 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> |