diff options
Diffstat (limited to 'doc/html/designer-manual-6.html')
-rw-r--r-- | doc/html/designer-manual-6.html | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/doc/html/designer-manual-6.html b/doc/html/designer-manual-6.html index 50e109a61..8881aae6d 100644 --- a/doc/html/designer-manual-6.html +++ b/doc/html/designer-manual-6.html @@ -104,7 +104,7 @@ int main( int argc, char *argv[] ) { TQ_OBJECT public: - CreditForm( <a href="ntqwidget.html">TQWidget</a>* parent = 0, const char* name = 0, + CreditForm( <a href="tqwidget.html">TQWidget</a>* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); ~CreditForm(); public slots: @@ -117,7 +117,7 @@ int main( int argc, char *argv[] ) #include <<a href="qspinbox-h.html">ntqspinbox.h</a>> #include "creditform.h" - CreditForm::CreditForm( <a href="ntqwidget.html">TQWidget</a>* parent, const char* name, + CreditForm::CreditForm( <a href="tqwidget.html">TQWidget</a>* parent, const char* name, bool modal, WFlags fl ) : CreditFormBase( parent, name, modal, fl ) { @@ -200,12 +200,12 @@ INCLUDEPATH += $(TQTDIR)/tools/designer/uilib <li><!-- index Signals and Slots!Connecting to Close a Dialog --><p>We'll now handle the signals and slots connections. Invoke the <em>View and Edit Connections</em> dialog and connect the credit dialog button's clicked() signal to a new creditDialog() custom slot (which is created by clicking the <b>Edit Slots...</b> button). Now connect the Quit button's<!-- index clicked() --> <tt>clicked()</tt> signal to the dialog's<!-- index accept() --> <tt>accept()</tt> function.</p> </ol><p>Save the form and call it <tt>mainform.ui</tt>. (Press <b>Ctrl+S</b> and enter the filename.) In the next section we'll write the code for loading and launching the dynamic dialog directly in <em>TQt Designer</em>.</p> <h5><a name="2-3-2"></a>Loading and Executing a Dynamic Dialog</h5> -<!-- index Dynamic Dialogs!Loading and Executing --><!-- index Dialogs!Dynamic --><!-- index Forms!Forward declarations --><!-- index Forward declarations --><!-- index Includes --><p>We'll now add the code to invoke the credit dialog. Before we can do this we need to add the widget factory's header file to the form. Click the Source tab in the Object Hierarchy. Right click Includes (in Implementation), then click <b>New</b>. Type in '<tt><ntqwidgetfactory.h></tt>', then press <b>Enter</b>. Because we will need to access the spin box in the dynamic dialog we must add its header file. Right click Includes (in Implmentation), then click <b>New</b>. Type in '<tt><ntqspinbox.h></tt>', then press <b>Enter</b>.</p> +<!-- index Dynamic Dialogs!Loading and Executing --><!-- index Dialogs!Dynamic --><!-- index Forms!Forward declarations --><!-- index Forward declarations --><!-- index Includes --><p>We'll now add the code to invoke the credit dialog. Before we can do this we need to add the widget factory's header file to the form. Click the Source tab in the Object Hierarchy. Right click Includes (in Implementation), then click <b>New</b>. Type in '<tt><tqwidgetfactory.h></tt>', then press <b>Enter</b>. Because we will need to access the spin box in the dynamic dialog we must add its header file. Right click Includes (in Implmentation), then click <b>New</b>. Type in '<tt><ntqspinbox.h></tt>', then press <b>Enter</b>.</p> <p>In our main form we created a slot called <tt>creditDialog()</tt>. We will implement this slot directly in <em>TQt Designer</em> and use it to load and execute the dynamic dialog. The code is taken from <tt>qt/tools/designer/examples/receiver1/mainform.ui.h</tt> which contains the C++ implementation of <tt>mainform.ui</tt>'s slots.</p> <pre> void MainForm::creditDialog() { <a href="ntqdialog.html">TQDialog</a> *creditForm = (TQDialog *) - TQWidgetFactory::<a href="ntqwidgetfactory.html#create">create</a>( "../credit/creditformbase.ui" ); + TQWidgetFactory::<a href="tqwidgetfactory.html#create">create</a>( "../credit/creditformbase.ui" ); // Set up the dynamic dialog here if ( creditForm-><a href="ntqdialog.html#exec">exec</a>() ) { @@ -217,7 +217,7 @@ INCLUDEPATH += $(TQTDIR)/tools/designer/uilib delete creditForm; } </pre> - <p>The<!-- index create() --> <tt>create()</tt> function is a static <a href="ntqwidgetfactory.html">TQWidgetFactory</a> function. It loads the specified<!-- index .ui --> <tt>.ui</tt> file and returns a pointer to the toplevel <a href="ntqwidget.html">TQWidget</a> created from the<!-- index .ui --> <tt>.ui</tt> file. We have cast the pointer to <a href="ntqdialog.html">TQDialog</a> since we know that the <tt>creditformbase.ui</tt> file defines a <a href="ntqdialog.html">TQDialog</a>. After creating the dialog we<!-- index exec() --> <tt>exec()</tt> it. If the user clicked <b>OK</b> the dialog returns Accepted and we enter the body of the <tt>if</tt> statement. We want to know the amount of credit that the user selected. We call the<!-- index child() --> <tt>child()</tt> function on the dialog passing it the name of the widget we're interested in. The<!-- index child() --> <tt>child()</tt> function returns a pointer to the widget with the name we passed, or returns 0 if no widget of that name was found. In the example we call<!-- index child() --> <tt>child()</tt> to get a pointer to the 'amountSpinBox'. If the pointer we get back is not 0 we set the rating text to the amount in the dialog's spin box. At the end we delete the dynamic dialog. Deleting the dialog ensures that we free up its resources as soon as it is no longer required.</p> + <p>The<!-- index create() --> <tt>create()</tt> function is a static <a href="tqwidgetfactory.html">TQWidgetFactory</a> function. It loads the specified<!-- index .ui --> <tt>.ui</tt> file and returns a pointer to the toplevel <a href="tqwidget.html">TQWidget</a> created from the<!-- index .ui --> <tt>.ui</tt> file. We have cast the pointer to <a href="ntqdialog.html">TQDialog</a> since we know that the <tt>creditformbase.ui</tt> file defines a <a href="ntqdialog.html">TQDialog</a>. After creating the dialog we<!-- index exec() --> <tt>exec()</tt> it. If the user clicked <b>OK</b> the dialog returns Accepted and we enter the body of the <tt>if</tt> statement. We want to know the amount of credit that the user selected. We call the<!-- index child() --> <tt>child()</tt> function on the dialog passing it the name of the widget we're interested in. The<!-- index child() --> <tt>child()</tt> function returns a pointer to the widget with the name we passed, or returns 0 if no widget of that name was found. In the example we call<!-- index child() --> <tt>child()</tt> to get a pointer to the 'amountSpinBox'. If the pointer we get back is not 0 we set the rating text to the amount in the dialog's spin box. At the end we delete the dynamic dialog. Deleting the dialog ensures that we free up its resources as soon as it is no longer required.</p> <p>We used the<!-- index child() --> <tt>child()</tt> to gain access to a widget within the dynamic dialog, passing it the name of the widget we were interested in. In some situations we might not know what a widget is called. We can access the first widget of a specified class by calling<!-- index child() --> <tt>child()</tt> with a null widget name and a classname, e.g. <tt>child(0,"TQPushButton")</tt>. This will return a pointer to the first <a href="ntqpushbutton.html">TQPushButton</a> it finds (or 0 if there isn't one). If you want pointers to all the widgets of a given class you can call the<!-- index TQObject::queryList() --> <tt>TQObject::queryList()</tt> function, passing it the name of the class. It returns a <a href="tqobjectlist.html">TQObjectList</a> pointer which points to every object in the dialog that is derived from the given class. See the online <a href="http://doc.trolltech.com/tqobject.html">TQObject</a> documentation for further details.</p> <h5><a name="2-3-3"></a>Implementing Slots for Dynamic Dialogs</h5> <!-- index Signals and Slots!Dynamic Dialogs --><!-- index Dynamic Dialogs --><p>There is one outstanding issue that we haven't addressed: the dynamic dialog does not have the behaviour of the original credit dialog because we have not implemented the <tt>setAmount()</tt> slot. We can implement slots for dynamic dialogs by creating a <a href="tqobject.html">TQObject</a> subclass. We then create an instance of this subclass and pass a pointer to it to the<!-- index TQWidgetFactory::create() --> <tt>TQWidgetFactory::create()</tt> function which will connect the dynamic dialog's signals to the slots implemented in our subclass.</p> @@ -226,7 +226,7 @@ INCLUDEPATH += $(TQTDIR)/tools/designer/uilib { Receiver *receiver = new Receiver; <a href="ntqdialog.html">TQDialog</a> *creditForm = (TQDialog *) - TQWidgetFactory::<a href="ntqwidgetfactory.html#create">create</a>( "../credit/creditformbase.ui", receiver ); + TQWidgetFactory::<a href="tqwidgetfactory.html#create">create</a>( "../credit/creditformbase.ui", receiver ); receiver->setParent( creditForm ); // Set up the dynamic dialog here @@ -298,7 +298,7 @@ private: <p align="center"><b> Compiling vs Dynamically Loading Dialogs</b></p> <!-- index Dynamic Dialogs!Compared with Compiling --><!-- index Dynamic Dialogs!Subclassing --><!-- index Subclassing!Dynamic Dialogs --><p>The differences between using a 'compiled in'<!-- index .ui --> <tt>.ui</tt> file and a dynamically loaded<!-- index .ui --> <tt>.ui</tt> file are these:</p> <ul><li><p>Dynamic dialogs cannot have any C++ code in the<!-- index .ui --> <tt>.ui</tt> file; any custom slots must be implemented via a <a href="tqobject.html">TQObject</a> subclass. Compiled dialogs can contain code either in the<!-- index .ui --> <tt>.ui</tt> file or in a subclass.</p> -<li><p>Dynamic dialogs will load slower because the<!-- index .ui --> <tt>.ui</tt> file must be read and a <a href="ntqwidget.html">TQWidget</a> instance instantiated based on the<!-- index .ui --> <tt>.ui</tt> file's parse tree. Compiled code will load much faster because no file reading or parsing is necessary. Note that the user may not notice any difference in speed since the difference may be mere fractions of a second.</p> +<li><p>Dynamic dialogs will load slower because the<!-- index .ui --> <tt>.ui</tt> file must be read and a <a href="tqwidget.html">TQWidget</a> instance instantiated based on the<!-- index .ui --> <tt>.ui</tt> file's parse tree. Compiled code will load much faster because no file reading or parsing is necessary. Note that the user may not notice any difference in speed since the difference may be mere fractions of a second.</p> <li><p>Dynamic dialogs allow you to change the<!-- index .ui --> <tt>.ui</tt> file independently of the code so long as none of the changes impact the code. This means that you can change the appearance of the form, e.g. move widgets and lay them out differently. If you want to change a compiled dialog you must change the<!-- index .ui --> <tt>.ui</tt> file and recompile. If you are building an application and want your customers to be able to customize aspects of the user interface you can give them a copy of <em>TQt Designer</em> (if your license permits this) and use dynamic dialogs.</p> </ul></blockquote> <!-- eof --> |