?? designer-manual-8.html
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/tools/designer/book/chap-customizing.leaf:3 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Customizing and Integrating Qt Designer</title><style type="text/css"><!--h3.fn,span.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><p align="right">[<a href="designer-manual-7.html">Prev: Creating Database Applications</a>] [<a href="designer-manual.html">Home</a>] [<a href="designer-manual-9.html">Next: Reference: Key Bindings</a>]</p><h2 align="center">Customizing and Integrating Qt Designer</h2><h3><a name="1"></a>Customizing Qt Designer</h3><p><em>Qt Designer</em> can be customized in two ways: you can add custom widgets, and you can change aspects of how <em>Qt Designer</em> works. Custom widgets are covered in <a href="designer-manual-6.html">Creating Custom Widgets</a>. This section will focus on customizing <em>Qt Designer</em> itself.</p><p><em>Qt 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>Qt 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>Qt Designer</em> will remember the sizes and positions of the toolbars and the dockable windows. You can change <em>Qt 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>Qt 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><h4><a name="1-1"></a>Qt Designer's Code Editor</h4><p>The code editor is available if an Editor plugin is installed. The C++ Editor plugin is installed by default.</p><!-- index Keypresses (Qt 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><a name="2"></a>Creating and Using Templates</h3><!-- index Creating Templates --><!-- index Templates!Creating and Using --><p><em>Qt 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><h4><a name="2-1"></a>Simple Templates</h4><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><p>First we'll create the simple template.</p><ol type=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>Qt 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><a name="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>Qt 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>Qt 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 <a href="designer-manual-6.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>Qt 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><a name="3"></a>Integrating Qt Designer with Visual Studio</h3><p><em>Qt Designer</em> can be integrated into Visual Studio using the<!-- index qmsdev.dsp --> <tt>qmsdev.dsp</tt> file that is supplied with Qt.</p><!-- index Visual Studio --><p>Start up Visual Studio and click <b>File|Open Workspace</b>. Open <tt>%QTDIR%</tt>\tools\designer\integration\qmsdev\qmsdev.dsp. Click <b>Build|Set Active Configuration</b> and in the list click 'QMsDev - Win32 Release', then click <b>OK</b>. Now click <b>Build|Build qmsdev.dll</b>. You should now copy the file <tt>%QTDIR%</tt>\tools\designer\integration\qmsdev\Release\qmsdev.dll into <tt>Microsoft Visual Studio\Common\MSDev98\AddIns</tt>. Now click <b>Tools|Customize</b>. Click the Add-in Macro Files tab, then click the <b>Browse</b> button. Change the file type to 'Add-ins (.dll)' and navigate to <tt>Microsoft Visual Studio\Common\MSDev98\AddIns</tt>. Click the<!-- index qmsdev.dll --> <tt>qmsdev.dll</tt> file, click <b>Open</b>, then click <b>Close</b>.</p><p>A new toolbar will appear in Visual Studio with the following toolbar buttons:</p><ul><li><p>New Qt Project -- A small application wizard</p><li><p>Generate Qt Project -- Runs <tt>qmake</tt> (or the functionally equivalent <tt>tmake</tt>) with a<!-- index .pro --> <tt>.pro</tt> file</p><li><p>New Qt Dialog -- Add an empty Qt Dialog to the active project</p><li><p>Qt GUI Designer -- Run <em>Qt Designer</em></p><li><p>Use Qt -- Add the Qt libraries to the active project</p><li><p>Add MOC -- Add the <tt>moc</tt> precompiler to the active file</p><li><p>Add UIC -- Add the <tt>uic</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>Qt Designer</em>.</p><!-- index Macros!Q_OBJECT --><!-- index Q_OBJECT --><p>If you create a<!-- index .cpp --> <tt>.cpp</tt> file which contains the <tt>Q_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>Q_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>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -