<h2align="center">Customizing and Integrating TQt Designer</h2>
<h3><aname="1"></a>Customizing TQt Designer</h3>
<p><em>TQt Designer</em> can be customized in two ways: you can add custom widgets, and you can change aspects of how <em>TQt Designer</em> works. Custom widgets are covered in <ahref="designer-manual-7.html">Creating Custom Widgets</a>. This section will focus on customizing <em>TQt Designer</em> itself.</p>
<p><em>TQt Designer</em>'s toolbars are all dockable so they can be dragged by their toolbar handles and arranged how you like. The Files, Object Hierarchy, Property Editor and Output Windows are also dockable so you can also drag them to the positions that you prefer. You can also make them into floating windows by dragging them outside <em>TQt Designer</em>'s dock areas.</p>
<p>General preferences can be set by clicking <b>Edit|Preferences</b> to invoke the <em>Preferences</em> dialog. If you check the 'Restore Last Workspace on Startup' checkbox then <em>TQt Designer</em> will remember the sizes and positions of the toolbars and the dockable windows. You can change <em>TQt Designer</em>'s main window background either by selecting a color or a pixmap. You can also switch off the grid (uncheck Show Grid) since using layouts makes the grid redundant.</p>
<!-- index Plugins --><!-- index Code Editing!Preferences --><!-- index Preferences!Code Editing --><p>The <em>Preferences</em> dialog may have additional tabs, depending on what plugins you have installed. We'll describe the C++ Editor tab since this is installed by default.</p>
<p>The C++ Editor tab is used to set your preferred fonts for syntax highlighting in <em>TQt Designer</em>'s code editor. The base font for all elements is set in the 'Standard' element which is the last item in the list. If you want one font to be used throughout then set the 'Standard' font and all the other elements will inherit its setting.</p>
<p>The code editor is available if an Editor plugin is installed. The C++ Editor plugin is installed by default.</p>
<!-- index Keypresses (TQt Designer's code editor) --><p>The code editor provides the following keystrokes:</p>
<ul><li><p>Left Arrow -- Moves the cursor one character left</p>
<li><p>Right Arrow -- Moves the cursor one character right</p>
<li><p>Up Arrow -- Moves the cursor one line up</p>
<li><p>Down Arrow -- Moves the cursor one line down</p>
<li><p>Page Up -- Moves the cursor one page up</p>
<li><p>Page Down -- Moves the cursor one page down</p>
<li><p>Backspace -- Deletes the character to the left of the cursor</p>
<li><p>Home -- Moves the cursor to the beginning of the line</p>
<li><p>End -- Moves the cursor to the end of the line</p>
<li><p>Delete -- Deletes the character to the right of the cursor</p>
<li><p>Ctrl+A -- Moves the cursor to the beginning of the line</p>
<li><p>Ctrl+B -- Moves the cursor one character left</p>
<li><p>Ctrl+C -- Copies the selected text to the clipboard (also Ctrl+Insert under Windows)</p>
<li><p>Ctrl+D -- Deletes the character to the right of the cursor</p>
<li><p>Ctrl+E -- Moves the cursor to the end of the line</p>
<li><p>Ctrl+F -- Invokes the <em>Find Text</em> dialog</p>
<li><p>Ctrl+G -- Invokes the <em>Goto Line</em> dialog</p>
<li><p>Ctrl+H -- Deletes the character to the left of the cursor</p>
<li><p>Ctrl+I -- Indent the line or selected text that contains the cursor</p>
<li><p>Alt+I -- Starts incremental search (see below)</p>
<li><p>Ctrl+K -- Deletes from the cursor position to the end of the line</p>
<li><p>Ctrl+N -- Moves the cursor one line down</p>
<li><p>Ctrl+P -- Moves the cursor one line up</p>
<li><p>Ctrl+R -- Invokes the <em>Replace Text</em> dialog</p>
<li><p>Ctrl+V -- Pastes the clipboard text into line edit (also Shift+Insert under Windows)</p>
<li><p>Ctrl+X -- Cuts the marked text, copy to clipboard (also Shift+Delete under Windows)</p>
<li><p>Ctrl+Y -- Redoes the last operation</p>
<li><p>Ctrl+Z -- Undoes the last operation</p>
<li><p>Ctrl+Left Arrow -- Moves the cursor one word left</p>
<li><p>Ctrl+Right Arrow -- Moves the cursor one word right</p>
<li><p>Ctrl+Up Arrow -- Moves the cursor one word up</p>
<li><p>Ctrl+Down Arrow -- Moves the cursor one word down</p>
<li><p>Ctrl+Home Arrow -- Moves the cursor to the beginning of the text</p>
<li><p>Ctrl+End Arrow -- Moves the cursor to the end of the text</p>
<li><p>Tab -- Completion (see below)</p>
</ul><p>To select (mark) text hold down the Shift key whilst pressing one of the movement keystrokes, for example, <b>Shift+Right Arrow</b> will select the character to the right, and <b>Shift+Ctrl+Right Arrow</b> will select the word to the right, etc.</p>
<p>Pressing <b>Alt+I</b> starts incremental search. The characters you type will appear in the Incremental Search line edit in the Search toolbar and the cursor will be moved to the first matching text in the editor. As you type the search will continue. Press <b>Return</b> to move to the next match and press <b>Esc</b> to cancel the search at the position you've reached.</p>
<p>Pressing <b>Tab</b> after you've typed one or more characters invokes completion. Completion works like this: start typing some text then press <b>Tab</b>. If the editor can find another item of text that begins with the same characters it will complete your text for you; if it finds more than one possibility it will pop up a list of choices. You can use the arrow keys to choose a piece of text then press <b>Return</b>, or press <b>Esc</b> to continue typing. You can switch off completion in the <em>Preferences</em> dialog.</p>
<p>When you enter <tt>-></tt> or <tt>.</tt> the editor will pop up a command completion list; use the arrow keys to move to the item you want and press <b>Return</b>, or press <b>Esc</b> to ignore the list.</p>
<h3><aname="2"></a>Creating and Using Templates</h3>
<!-- index Creating Templates --><!-- index Templates!Creating and Using --><p><em>TQt Designer</em> supports two approaches to creating template forms. The simplest approach involves little more than saving a<!-- index .ui --><tt>.ui</tt> file into the templates directory. The second approach involves creating a container widget class to be used as a base class for forms that use the template. We will explain both techniques.</p>
<p>These templates are most useful when you want to create a whole set of forms which all have some common widgets. For example, you might have a project that will require many forms, all of which need to be branded with a company name and logo.</p>
<oltype=1><li><p>Click <b>File|New</b> to invoke the <em>New File</em> dialog. Click the Dialog template then click <b>OK</b>.</p>
<li><p>Click the <b>Text Label</b> toolbar button, then click near the top left of the form. Change the font Point Size property to 16 and change the <em>text</em> property to your or your company's name. Click the <b>Line</b> toolbar button, then click the form below the label; click Horizontal on the pop-up menu.</p>
<li><p>Select the label and the line. (<b>Ctrl+Click</b> the form, then drag the rubber band so that it touches or includes the line and the label.) Press <b>Ctrl+L</b> to lay them out vertically.</p>
<li><p>Click the <b>Save</b> toolbar button. In the <em>Save As</em> dialog, navigate to <em>TQt Designer</em>'s templates directory, e.g. (<tt>qt/tools/designer/templates</tt>. Type in the name 'Simple_Dialog.ui' and click <b>Save</b>.</p>
<li><p>Right click the form in the Forms list, then click Remove form from project.</p>
</ol><p>Now that we have the simple template we are ready to use it. Click <b>File|New</b> to invoke the <em>New File</em> dialog. One of the templates that will appear is 'Simple Dialog'. Click the simple dialog, then click <b>OK</b>. A new form will appear with the same widgets and layout as the template. Add any other widgets and functionality. When you attempt to save the form you will be prompted for a new form name.</p>
<h4><aname="2-2"></a>Base-class Templates</h4>
<!-- index Templates!Base Class Templates --><p>These templates are useful when you want to provide some default functionality that all the forms based on the base class can inherit. In our example we'll use a class called <b>SizeAware</b> that remembers and restores its size as the basis of a template. We won't describe the class itself, but will focus instead on making use of it as a <em>TQt Designer</em> template. The source for the class is in <tt>qt/tools/designer/examples/sizeaware</tt>.</p>
<p>The template can either be based on a custom widget or on any existing container widget.</p>
<p>If you want to base the template on a custom widget you must first add it to <em>TQt Designer</em>'s custom widgets. Click <b>Tools|Custom|Edit Custom Widgets</b> to invoke the <em>Edit Custom Widgets</em> dialog. (This dialog is explained in more detail in <ahref="designer-manual-7.html#1">Simple Custom Widgets</a>.) Click <b>New Widget</b>. Change the Class from 'MyCustomWidget' to 'SizeAware'. Click the Headerfile ellipsis button and select the file <tt>qt/tools/designer/examples/sizeaware/sizeaware.h</tt>. Check the Container Widget checkbox. This class provides two properties. Click the Properties tab. Click <b>New Property</b> and change the property name to 'company'. Click the <b>New Property</b> again and change the property name to 'settingsFile'. Click <b>Close</b>.</p>
<p>To create a template, based on an existing widget or on your own custom widget, click <b>File|Create Template</b> to invoke the <em>Create Template</em> dialog. Change the Template Name to 'SizeAware' and click the SizeAware base class, then click <b>Create</b>. The dialog will create the template and close itself immediately. Close <em>TQt Designer</em> and restart it.</p>
<p>A new template, 'SizeAware' is now available from the list of templates. Click <b>File|New</b>, click SizeAware and click <b>OK</b>. Note that the two properties, company and settingsFile, are available in the Properties window. Any forms based on this template will remember their size and resize when reloaded. (In practical applications having one settingsFile per form is not recommended, so this template would only really be useful for applications that have a single main window.)</p>
<h3><aname="3"></a>Integrating TQt Designer with Visual Studio</h3>
<p>By default, <em>TQt Designer</em> is integrated into Visual Studio 6.0 when TQt is installed. Visual Studio.Net does not support this integration.</p>
<!-- index Visual Studio --><p>If installed successfully, a toolbar should be provided in Visual Studio with the following buttons:</p>
<ul><li><p>New TQt Project -- A small application wizard</p>
<li><p>New TQt Dialog -- Add an empty TQt Dialog to the active project, or add an existing dialog</p>
<li><p>TQt GUI Designer -- Run <em>TQt Designer</em></p>
<li><p>Open TQt Project -- Runs <tt>qmake</tt> with a<!-- index .pro --><tt>.pro</tt> file</p>
<li><p>Write TQt Project -- Saves the current VS project as a<!-- index .pro --><tt>.pro</tt> file</p>
<li><p>Use TQt -- Add the TQt libraries to the active project</p>
<li><p>Add MOC -- Add the <tt>moc</tt> precompiler to the active file</p>
</ul><p>Double clicking a<!-- index .ui --><tt>.ui</tt> file in the workspace overview will now launch <em>TQt Designer</em>.</p>
<!-- index Macros!TQ_OBJECT --><!-- index TQ_OBJECT --><p>If you create a<!-- index .cpp --><tt>.cpp</tt> file which contains the <tt>TQ_OBJECT</tt> macro you will need an additional file which is generated by the <tt>moc</tt> to be included in your project. For example, if you have 'file.cpp', then the last line would be <tt>#include "file.moc"</tt> and the additional file would be called 'file.moc'. To ensure that Visual Studio executes the <tt>moc</tt> and generates this file you must create a custom dependency. Double click the<!-- index .cpp --><tt>.cpp</tt> file (in your project workspace) that contains the <tt>TQ_OBJECT</tt> macro. Click the <b>Add MOC</b> toolbar button; this will create an empty<!-- index .moc --><tt>.moc</tt> file in your project workspace. Right click the newly created<!-- index .moc --><tt>.moc</tt> file, then click <b>Settings</b> from the pop-up menu to invoke the Project Settings dialog. Click the Custom Build tab. Click the <b>Dependencies</b> button to pop up the User Defined Dependencies dialog. Type in <tt>$(InputDir)\$(InputPath)</tt>, then press <b>Return</b>. Click <b>OK</b> to leave the Dependencies dialog, then click <b>OK</b> to leave the Project Settings dialog.</p>
<p>If you wish to delete the add-in remove it from the toolbar then delete the<!-- index qmsdev.dll --><tt>qmsdev.dll</tt> file from the add-ins directory.</p>
<h4><aname="3-1"></a>Creating Makefiles without qmake</h4>
<!-- index Makefiles --><p>The <tt>qmake</tt> tool provided with TQt can create Makefiles appropriate to your platform based on<!-- index .pro --><tt>.pro</tt> project files. This section describes the dependencies involved in building a TQt application and gives a couple of simple example Makefiles. This section assumes that you have a good understanding of Makefiles.</p>
<!-- index Macros!TQ_OBJECT --><!-- index TQ_OBJECT --><p><em>TQt Designer</em> produces<!-- index .ui --><tt>.ui</tt> files which are used to generate<!-- index .h --><tt>.h</tt> and<!-- index .cpp --><tt>.cpp</tt> files for the compiler to compile. The<!-- index .ui --><tt>.ui</tt> files are processed by <tt>uic</tt>. Classes which inherit from <ahref="tqobject.html">TQObject</a>, e.g. those which use slots and signals, require an additional<!-- index .cpp --><tt>.cpp</tt> file to be generated. These files are generated by the <tt>moc</tt> and are named '<em>moc_</em>file.cpp' where the original<!-- index .cpp --><tt>.cpp</tt> file is called 'file.cpp'. If your<!-- index .cpp --><tt>.cpp</tt> file contains the <tt>TQ_OBJECT</tt> macro an additional file 'file.moc' should be generated which must be <tt>#include</tt>d in the<!-- index .cpp --><tt>.cpp</tt>, normally at the end. This requires an extra dependency being created.</p>
<p>Processing<!-- index .ui --><tt>.ui</tt> files with <tt>uic</tt> is done <em>twice</em>:</p>
<pre>
uic myform.ui -o myform.h
uic myform.ui -i myform.h -o myform.cpp
</pre>
<p>The first execution creates the header file, the second creates the<!-- index .cpp --><tt>.cpp</tt> file. If you wish to subclass a form you can use <tt>uic</tt> to generate subclass skeletons:</p>
<pre>
uic formbase.ui -o formbase.h
uic formbase.ui -i formbase.h -o formbase.cpp
uic -subdecl Form formbase.h formbase.ui -o form.h
uic -subimpl Form form.h formbase.ui -o form.cpp
</pre>
<p>First we generate the header and implementation file for our base class. Then we generate the header and implementation skeletons for our subclass. Note that the use of <tt>uic</tt> to generate skeletons is not something that would be done in a Makefile, we mention it here because it can be useful for command line users. Note also that the command line for <tt>-subdecl</tt> and for <tt>-subimpl</tt> are subtly different.</p>
<p>We'll look at a simple Makefile to see the dependencies in practice.</p>
<pre>
myapp: moc_myform.o myform.o main.o
g++ -lqt -o myapp moc_myform.o myform.o main.o
main.o: main.cpp
g++ -o main.o main.cpp
moc_myform.o: moc_myform.cpp
g++ -o moc_myform.o moc_myform.cpp
moc_myform.cpp: myform.h
moc myform.h -o moc_myform.cpp
myform.o: myform.cpp
g++ -o myform.o myform.cpp
myform.cpp: myform.h myform.ui
uic myform.ui -i myform.h -o myform.cpp
myform.h: myform.ui
uic myform.ui -o myform.h
</pre>
<p>Note that you may need to include the full path to the commands in your Makefile, and under Windows the filenames are<!-- index moc.exe --><tt>moc.exe</tt> and<!-- index uic.exe --><tt>uic.exe</tt>.</p>
<p>In Unix/Linux environments the <tt>make</tt> command may be able to do more for us, so we should be able to use a simpler Makefile like this:</p>
<pre>
myapp: moc_myform.o myform.o main.o
g++ -lq -o $@ $^
%.o: %.cpp
g++ -o $^ $@
moc_%.cpp: %.h
moc $^ -o $@
myform.cpp: myform.h myform.ui
uic myform.ui -i myform.h -o myform.cpp
myform.h: myform.ui
uic myform.ui -o myform.h
</pre>
<p>To see more sophisticated Makefiles simply generate them using <tt>qmake</tt> on any of your TQt projects or any of the examples supplied with TQt.</p>
<!-- index Foreign File Formats --><p>To import a file in a supported foreign file format click <b>File|Open</b>, then click the File Type combobox to choose the file type you wish to load. Click the required file and <em>TQt Designer</em> will convert and load the file.</p>
<p>The filters that <em>TQt Designer</em> uses to read foreign file formats are 'works in progress'. You may have different filters available in your version of <em>TQt Designer</em> than those described here. The easiest way to see which filters are available is to invoke the file open dialog; all your filters are listed in the File Type combobox.</p>
<!-- index Foreign File Formats!TQt Architect --><!-- index TQt Architect --><p><ahref="http://qtarch.sourceforge.net/">TQt Architect</a> is a free GUI builder for TQt written by Jeff Harris and Klaus Ebner. The<!-- index .dlg --><tt>.dlg</tt> extension is associated with TQt Architect dialog files.</p>
<p><em>TQt Designer</em> can read files generated by TQt Architect version 2.1 and above. When given a<!-- index .dlg --><tt>.dlg</tt> file from a previous version of TQt Architect, <em>TQt Designer</em> tells you how to convert it to the file format of version 2.1. (The conversion procedure varies depending on the version of the<!-- index .dlg --><tt>.dlg</tt> file.)</p>
<p>The import filter does a good job of importing<!-- index .dlg --><tt>.dlg</tt> files; the result is almost identical to what you get in TQt Architect. However, the C++ code that uses the dialogs will probably need some adaptation.</p>
<p>There are a few drawbacks to converting TQt Architect files to <em>TQt Designer</em>'s format due to differences between the two tools; these are listed below:</p>
<ul><li><p>Layout spacing and margins</p>
<p>If the<!-- index .dlg --><tt>.dlg</tt> file layouts use the TQt Architect defaults for layout spacing and margins, <em>TQt Designer</em> will override these with its standard defaults. You can change the "layoutSpacing" and "layoutMargin" properties manually afterwards if necessary.</p>
<li><p>Layout stretches and spacings</p>
<p>TQt Architect gives access to more features of TQt's layout system than <em>TQt Designer</em>, namely stretches and spacings. TQt Designer will attempt to cope with<!-- index .dlg --><tt>.dlg</tt> files that use these features, but sometimes the resizing will not be what you want. The solution typically involves setting the "sizePolicy" properties of some widgets and inserting or deleting spacers.</p>
<li><p>Mixing managed and unmanaged widgets</p>
<p>TQt Architect allows a widget to have some child widgets managed by a layout and other child widgets with fixed positions. When presented with a<!-- index .dlg --><tt>.dlg</tt> file that uses this facility, <em>TQt Designer</em> will silently put the fixed position widgets into the layout.</p>
<li><p>Pixmaps</p>
<p><em>TQt Designer</em> ignores pixmaps specified in<!-- index .dlg --><tt>.dlg</tt> files. These have to be restored manually in <em>TQt Designer</em>.</p>
<!-- index Foreign File Formats!Glade --><!-- index Glade --><p><ahref="http://glade.pn.org/">Glade</a> is a free GUI builder for GTK+ and GNOME written by Damon Chaplin. The<!-- index .glade --><tt>.glade</tt> extension is associated with Glade files.</p>
<p><em>TQt Designer</em> has been tested with Glade files up to version 0.6.0 and might work with later versions as well.</p>
<p>Although Glade does not target TQt, the layout system and the widget set of GTK+ are similar to those of TQt, so the filter will retain most of the information in the<!-- index .glade --><tt>.glade</tt> file.</p>
<p>There are some considerations regarding the conversion of Glade files, as listed below:</p>
<p>TQt displays an ampersand when a <ahref="ntqlabel.html">TQLabel</a> has no buddy. (A buddy is a widget that accepts focus on behalf of a <ahref="ntqlabel.html">TQLabel</a>.) Glade allows GtkLabel widgets with an (underlined) accelerator key but with no buddy. This is an error since users expect underlined characters to be accelerators. In this situation, TQt displays the ampersand itself instead of underlining the accelerator key. You should go over these <ahref="ntqlabel.html">TQLabel</a> widgets and set their "<em>buddy</em>" property.</p>
<p>GTK allows a layout position to be occupied by a placeholder. <em>TQt Designer</em> converts those placeholders into <ahref="ntqlabel.html">TQLabel</a>s whose text is "?" in red, so that you can find them and fix them manually.</p>
<p>TQt has equivalents for most GTK+ widgets, but Glade also supports GNOME, whose goal is to provide a complete desktop environment. Because TQt's scope is narrower, when <em>TQt Designer</em> encounters a widget it cannot convert, it replaces it with a label that indicates the problem. For example, a GnomePaperSelector will be replaced by a <ahref="ntqlabel.html">TQLabel</a> whose text is "GnomePaperSelector?" in red. If you are porting to KDE, you might want to use the corresponding KDE widget.</p>
<p>Other GTK+/GNOME widgets are only supported in certain contexts. For example, the GnomeDruid can be embedded in another widget, whereas the corresponding <ahref="ntqwizard.html">TQWizard</a> class cannot.</p>
<p>Glade supports editing of GnomeMessageBox, GtkFileSelection, GtkFontSelectionDialog and others. This is trivially achieved in TQt by means of a <ahref="ntqmessagebox.html">TQMessageBox</a> dialog, a <ahref="ntqfiledialog.html">TQFileDialog</a>, a <ahref="ntqfontdialog.html">TQFontDialog</a>, etc., in C++ code.</p>
<p><em>TQt Designer</em> only supports popup menus inside a <ahref="tqmainwindow.html">TQMainWindow</a>. If you need a stand-alone popup menu (presumably a context menu), you can easily write code that does this using <ahref="tqpopupmenu.html">TQPopupMenu</a>.</p>
<p>Glade provides size policies in the "Place" tab of the property editor. <em>TQt Designer</em> does not attempt to make use of the padding, expand, shrink and fill information, as the TQt defaults are usually good enough. In a few cases, you might have to set the "<em>sizePolicy</em>" property manually to obtain the effect you want.</p>
<li><p>GNOME standard icons</p>
<p>GNOME provides a large set of standard icons. <em>TQt Designer</em> will ignore references to these. If you are porting to KDE, you might want to manually set the standard KDE icons.</p>
<li><p>Packer layout</p>
<p>GTK+ provides a class called GtkPacker that provides for exotic layouts; TQt does not provide a <b>TQPackerLayout</b> and none is planned. <em>TQt Designer</em> will treat packer layouts as if they were vertical layouts and you will probably have to change them to whatever combination of layouts that produces the right effect.</p>
<li><p>Incorrectly-justified text after conversion</p>