summaryrefslogtreecommitdiffstats
path: root/doc/html/qwidgetfactory.html
blob: b2c39bf8cf328ff59024520f05e5b36110403c45 (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
<!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/tools/designer/uilib/qwidgetfactory.cpp:207 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QWidgetFactory Class</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>QWidgetFactory Class Reference</h1>

<p>The QWidgetFactory class provides for the dynamic creation of widgets
from Qt Designer .ui files.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qwidgetfactory-h.html">qwidgetfactory.h</a>&gt;</tt>
<p><a href="qwidgetfactory-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QWidgetFactory"><b>QWidgetFactory</b></a> ()</li>
<li class=fn>virtual <a href="#~QWidgetFactory"><b>~QWidgetFactory</b></a> ()</li>
<li class=fn>virtual QWidget * <a href="#createWidget"><b>createWidget</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;className, QWidget&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;name ) const</li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li class=fn>QWidget * <a href="#create"><b>create</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;uiFile, QObject&nbsp;*&nbsp;connector = 0, QWidget&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
<li class=fn>QWidget * <a href="#create-2"><b>create</b></a> ( QIODevice&nbsp;*&nbsp;dev, QObject&nbsp;*&nbsp;connector = 0, QWidget&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
<li class=fn>void <a href="#addWidgetFactory"><b>addWidgetFactory</b></a> ( QWidgetFactory&nbsp;*&nbsp;factory )</li>
<li class=fn>void <a href="#loadImages"><b>loadImages</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;dir )</li>
<li class=fn>QStringList <a href="#widgets"><b>widgets</b></a> ()</li>
<li class=fn>bool <a href="#supportsWidget"><b>supportsWidget</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;widget )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


<p> The QWidgetFactory class provides for the dynamic creation of widgets
from Qt Designer .ui files.
<p> This class basically offers two things:
<p> <ul>
<p> <li> Dynamically creating widgets from <a href="designer-manual.html">Qt
  Designer</a> user interface description files.
You can do this using the static function <a href="#create">QWidgetFactory::create</a>().
This function also performs signal and slot connections, tab
ordering, etc., as defined in the .ui file, and returns the
top-level widget in the .ui file. After creating the widget you can
use <a href="qobject.html#child">QObject::child</a>() and <a href="qobject.html#queryList">QObject::queryList</a>() to access child
widgets of this returned widget.
<p> <li> Adding additional widget factories to be able to create custom
widgets. See <a href="#createWidget">createWidget</a>() for details.
<p> </ul>
<p> This class is not included in the Qt library itself. To use it you
must link against <tt>libqui.so</tt> (Unix) or <tt>qui.lib</tt> (Windows), which is
built into <tt>INSTALL/lib</tt> if you built <em>Qt Designer</em> (<tt>INSTALL</tt> is
the directory where Qt is installed ).
<p> If you create a <a href="qmainwindow.html">QMainWindow</a> using a QWidgetFactory, be aware that
it already has a central widget. Therefore, you need to delete this
one before setting another one.
<p> See the "Creating Dynamic Dialogs from .ui Files" section of the <a href="designer-manual.html">Qt Designer manual</a> for an example. See
also the <a href="qwidgetplugin.html">QWidgetPlugin</a> class and the <a href="plugins-howto.html">Plugins documentation</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QWidgetFactory"></a>QWidgetFactory::QWidgetFactory ()
</h3> Constructs a QWidgetFactory. 
<h3 class=fn><a name="~QWidgetFactory"></a>QWidgetFactory::~QWidgetFactory ()<tt> [virtual]</tt>
</h3> 
Destructor.

<h3 class=fn>void <a name="addWidgetFactory"></a>QWidgetFactory::addWidgetFactory ( <a href="qwidgetfactory.html">QWidgetFactory</a>&nbsp;*&nbsp;factory )<tt> [static]</tt>
</h3> Installs a widget factory <em>factory</em>, which normally contains
additional widgets that can then be created using a QWidgetFactory.
See <a href="#createWidget">createWidget</a>() for further details.

<h3 class=fn><a href="qwidget.html">QWidget</a>&nbsp;* <a name="create"></a>QWidgetFactory::create ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;uiFile, <a href="qobject.html">QObject</a>&nbsp;*&nbsp;connector = 0, <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )<tt> [static]</tt>
</h3>
<p> Loads the <em>Qt Designer</em> user interface description file <em>uiFile</em>
and returns the top-level widget in that description. <em>parent</em> and
<em>name</em> are passed to the constructor of the top-level widget.
<p> This function also performs signal and slot connections, tab
ordering, etc., as described in the .ui file. In <em>Qt Designer</em> it
is possible to add custom slots to a form and connect to them. If
you want these connections to be made, you must create a class
derived from <a href="qobject.html">QObject</a>, which implements all these slots. Then pass an
instance of the object as <em>connector</em> to this function. If you do
this, the connections to the custom slots will be done using the <em>connector</em> as slot.
<p> If something fails, 0 is returned.
<p> The ownership of the returned widget is passed to the caller.

<h3 class=fn><a href="qwidget.html">QWidget</a>&nbsp;* <a name="create-2"></a>QWidgetFactory::create ( <a href="qiodevice.html">QIODevice</a>&nbsp;*&nbsp;dev, <a href="qobject.html">QObject</a>&nbsp;*&nbsp;connector = 0, <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )<tt> [static]</tt>
</h3>  This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Loads the user interface description from device <em>dev</em>.

<h3 class=fn><a href="qwidget.html">QWidget</a>&nbsp;* <a name="createWidget"></a>QWidgetFactory::createWidget ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;className, <a href="qwidget.html">QWidget</a>&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;name ) const<tt> [virtual]</tt>
</h3>
Creates a widget of the type <em>className</em> passing <em>parent</em> and <em>name</em> to its constructor.
<p> If <em>className</em> is a widget in the Qt library, it is directly
created by this function. If the widget isn't in the Qt library,
each of the installed widget plugins is asked, in turn, to create
the widget. As soon as a plugin says it can create the widget it
is asked to do so. It may occur that none of the plugins can
create the widget, in which case each installed widget factory is
asked to create the widget (see <a href="#addWidgetFactory">addWidgetFactory</a>()). If the widget
cannot be created by any of these means, 0 is returned.
<p> If you have a custom widget, and want it to be created using the
widget factory, there are two approaches you can use:
<p> <ol type=1>
<p> <li> Write a widget plugin. This allows you to use the widget in
<em>Qt Designer</em> and in this QWidgetFactory. See the widget plugin
documentation for further details. (See the "Creating Custom
Widgets with Plugins" section of the <a href="designer-manual.html">Qt
    Designer manual</a> for an example.
<p> <li> Subclass QWidgetFactory. Then reimplement this function to
create and return an instance of your custom widget if <em>className</em> equals the name of your widget, otherwise return 0. Then
at the beginning of your program where you want to use the widget
factory to create widgets do a:
<pre>
    QWidgetFactory::<a href="#addWidgetFactory">addWidgetFactory</a>( new MyWidgetFactory );
    </pre>
 
where MyWidgetFactory is your QWidgetFactory subclass.
<p> </ol>

<h3 class=fn>void <a name="loadImages"></a>QWidgetFactory::loadImages ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;dir )<tt> [static]</tt>
</h3>
If you use a pixmap collection (which is the default for new
projects) rather than saving the pixmaps within the .ui XML file,
you must load the pixmap collection. QWidgetFactory looks in the
default <a href="qmimesourcefactory.html">QMimeSourceFactory</a> for the pixmaps. Either add it there
manually, or call this function and specify the directory where
the images can be found, as <em>dir</em>. This is normally the
directory called <tt>images</tt> in the project's directory.

<h3 class=fn>bool <a name="supportsWidget"></a>QWidgetFactory::supportsWidget ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;widget )<tt> [static]</tt>
</h3> Returns TRUE if the widget factory can create the specified <em>widget</em>;
otherwise returns FALSE. 
<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="widgets"></a>QWidgetFactory::widgets ()<tt> [static]</tt>
</h3> Returns the names of the widgets this factory can create. 
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<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>