Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 1460

qt4-doc-4.8.7-26.2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- designer-manual.qdoc -->
  <title>Qt 4.8: Creating Custom Widgets for Qt Designer</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li>Creating Custom Widgets for Qt Designer</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
  <link rel="prev" href="designer-using-custom-widgets.html" />
  <link rel="next" href="designer-creating-custom-widgets-extensions.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="designer-using-custom-widgets.html">Using Custom Widgets with Qt Designer</a>
<a class="nextPage" href="designer-creating-custom-widgets-extensions.html">Creating Custom Widget Extensions</a>
</p><p/>
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#getting-started">Getting Started</a></li>
<li class="level2"><a href="#providing-an-interface-description">Providing an Interface Description</a></li>
<li class="level2"><a href="#notes-on-the-function">Notes on the <tt>domXml()</tt> Function</a></li>
<li class="level1"><a href="#plugin-requirements">Plugin Requirements</a></li>
<li class="level1"><a href="#creating-well-behaved-widgets">Creating Well Behaved Widgets</a></li>
<li class="level1"><a href="#building-and-installing-the-plugin">Building and Installing the Plugin</a></li>
<li class="level2"><a href="#a-simple-plugin">A Simple Plugin</a></li>
<li class="level2"><a href="#splitting-up-the-plugin">Splitting up the Plugin</a></li>
<li class="level1"><a href="#related-examples">Related Examples</a></li>
</ul>
</div>
<h1 class="title">Creating Custom Widgets for Qt Designer</h1>
<span class="subtitle"></span>
<!-- $$$designer-creating-custom-widgets.html-description -->
<div class="descr"> <a name="details"></a>
<p><i>Qt Designer</i>'s plugin-based architecture allows user-defined and third party custom widgets to be edited just like you do with standard Qt widgets. All of the custom widget's features are made available to <i>Qt Designer</i>, including widget properties, signals, and slots. Since <i>Qt Designer</i> uses real widgets during the form design process, custom widgets will appear the same as they do when previewed.</p>
<p class="centerAlign"><img src="images/worldtimeclockplugin-example.png" alt="" /></p><p>The <a href="qtdesigner.html">QtDesigner</a> module provides you with the ability to create custom widgets in <i>Qt Designer</i>.</p>
<a name="getting-started"></a>
<h2>Getting Started</h2>
<p>To integrate a custom widget with <i>Qt Designer</i>, you require a suitable description for the widget and an appropriate <tt>.pro</tt> file.</p>
<a name="providing-an-interface-description"></a>
<h3>Providing an Interface Description</h3>
<p>To inform <i>Qt Designer</i> about the type of widget you want to provide, create a subclass of <a href="qdesignercustomwidgetinterface.html">QDesignerCustomWidgetInterface</a> that describes the various properties your widget exposes. Most of these are supplied by functions that are pure virtual in the base class, because only the author of the plugin can provide this information.</p>
<table class="generic">
<thead><tr class="qt-style"><th >Function</th><th >Description of the return value</th></tr></thead>
<tr valign="top" class="odd"><td ><tt>name()</tt></td><td >The name of the class that provides the widget.</td></tr>
<tr valign="top" class="even"><td ><tt>group()</tt></td><td >The group in <i>Qt Designer</i>'s widget box that the widget belongs to.</td></tr>
<tr valign="top" class="odd"><td ><tt>toolTip()</tt></td><td >A short description to help users identify the widget in <i>Qt Designer</i>.</td></tr>
<tr valign="top" class="even"><td ><tt>whatsThis()</tt></td><td >A longer description of the widget for users of <i>Qt Designer</i>.</td></tr>
<tr valign="top" class="odd"><td ><tt>includeFile()</tt></td><td >The header file that must be included in applications that use this widget. This information is stored in UI files and will be used by <tt>uic</tt> to create a suitable <tt>#includes</tt> statement in the code it generates for the form containing the custom widget.</td></tr>
<tr valign="top" class="even"><td ><tt>icon()</tt></td><td >An icon that can be used to represent the widget in <i>Qt Designer</i>'s widget box.</td></tr>
<tr valign="top" class="odd"><td ><tt>isContainer()</tt></td><td >True if the widget will be used to hold child widgets; false otherwise.</td></tr>
<tr valign="top" class="even"><td ><tt>createWidget()</tt></td><td >A <a href="qwidget.html">QWidget</a> pointer to an instance of the custom widget, constructed with the parent supplied. <b>Note:</b> createWidget() is a factory function responsible for creating the widget only. The custom widget's properties will not be available until load() returns.</td></tr>
<tr valign="top" class="odd"><td ><tt>domXml()</tt></td><td >A description of the widget's properties, such as its object name, size hint, and other standard <a href="qwidget.html">QWidget</a> properties.</td></tr>
<tr valign="top" class="even"><td ><tt>codeTemplate()</tt></td><td >This function is reserved for future use by <i>Qt Designer</i>.</td></tr>
</table>
<p>Two other virtual functions can also be reimplemented:</p>
<table class="generic">
<tr valign="top" class="odd"><td ><tt>initialize()</tt></td><td >Sets up extensions and other features for custom widgets. Custom container extensions (see <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a>) and task menu extensions (see <a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a>) should be set up in this function.</td></tr>
<tr valign="top" class="even"><td ><tt>isInitialized()</tt></td><td >Returns true if the widget has been initialized; returns false otherwise. Reimplementations usually check whether the <tt>initialize()</tt> function has been called and return the result of this test.</td></tr>
</table>
<a name="notes-on-the-function"></a>
<h3>Notes on the <tt>domXml()</tt> Function</h3>
<p>The <tt>domXml()</tt> function returns a UI file snippet that is used by <i>Qt Designer</i>'s widget factory to create a custom widget and its applicable properties.</p>
<p>Since Qt 4.4, <i>Qt Designer</i>'s widget box allows for a complete UI file to describe <b>one</b> custom widget. The UI file can be loaded using the <tt>&lt;ui&gt;</tt> tag. Specifying the &lt;ui&gt; tag allows for adding the &lt;customwidget&gt; element that contains additional information for custom widgets. The <tt>&lt;widget&gt;</tt> tag is sufficient if no additional information is required</p>
<p>If the custom widget does not provide a reasonable size hint, it is necessary to specify a default geometry in the string returned by the <tt>domXml()</tt> function in your subclass. For example, the <tt>AnalogClockPlugin</tt> provided by the <a href="designer-customwidgetplugin.html">Custom Widget Plugin</a> example, defines a default widgetgeometry in the following way:</p>
<pre class="qml">     ...
            <span class="string">&quot;  &lt;property name=\&quot;geometry\&quot;&gt;\n&quot;</span>
            <span class="string">&quot;   &lt;rect&gt;\n&quot;</span>
            <span class="string">&quot;    &lt;x&gt;0&lt;/x&gt;\n&quot;</span>
            <span class="string">&quot;    &lt;y&gt;0&lt;/y&gt;\n&quot;</span>
            <span class="string">&quot;    &lt;width&gt;100&lt;/width&gt;\n&quot;</span>
            <span class="string">&quot;    &lt;height&gt;100&lt;/height&gt;\n&quot;</span>
            <span class="string">&quot;   &lt;/rect&gt;\n&quot;</span>
            <span class="string">&quot;  &lt;/property&gt;\n&quot;</span>
     ...</pre>
<p>An additional feature of the <tt>domXml()</tt> function is that, if it returns an empty string, the widget will not be installed in <i>Qt Designer</i>'s widget box. However, it can still be used by other widgets in the form. This feature is used to hide widgets that should not be explicitly created by the user, but are required by other widgets.</p>
<p>A complete custom widget specification looks like:</p>
<pre class="cpp"> <span class="operator">&lt;</span>ui language<span class="operator">=</span><span class="string">&quot;c++&quot;</span><span class="operator">&gt;</span> displayname<span class="operator">=</span><span class="string">&quot;MyWidget&quot;</span><span class="operator">&gt;</span>
     <span class="operator">&lt;</span>widget <span class="keyword">class</span><span class="operator">=</span><span class="string">&quot;widgets::MyWidget&quot;</span> name<span class="operator">=</span><span class="string">&quot;mywidget&quot;</span><span class="operator">/</span><span class="operator">&gt;</span>
     <span class="operator">&lt;</span>customwidgets<span class="operator">&gt;</span>
         <span class="operator">&lt;</span>customwidget<span class="operator">&gt;</span>
             <span class="operator">&lt;</span><span class="keyword">class</span><span class="operator">&gt;</span>widgets<span class="operator">::</span>MyWidget<span class="operator">&lt;</span><span class="operator">/</span><span class="keyword">class</span><span class="operator">&gt;</span>
             <span class="operator">&lt;</span>addpagemethod<span class="operator">&gt;</span>addPage<span class="operator">&lt;</span><span class="operator">/</span>addpagemethod<span class="operator">&gt;</span>
             <span class="operator">&lt;</span>propertyspecifications<span class="operator">&gt;</span>
                 <span class="operator">&lt;</span>stringpropertyspecification name<span class="operator">=</span><span class="string">&quot;fileName&quot;</span> notr<span class="operator">=</span><span class="string">&quot;true&quot;</span> type<span class="operator">=</span><span class="string">&quot;singleline&quot;</span>
                 <span class="operator">&lt;</span>stringpropertyspecification name<span class="operator">=</span><span class="string">&quot;text&quot;</span> type<span class="operator">=</span><span class="string">&quot;richtext&quot;</span>
             <span class="operator">&lt;</span><span class="operator">/</span>propertyspecifications<span class="operator">&gt;</span>
         <span class="operator">&lt;</span><span class="operator">/</span>customwidget<span class="operator">&gt;</span>
     <span class="operator">&lt;</span><span class="operator">/</span>customwidgets<span class="operator">&gt;</span>
 <span class="operator">&lt;</span><span class="operator">/</span>ui<span class="operator">&gt;</span></pre>
<p>Attributes of the <tt>&lt;ui&gt;</tt> tag:</p>
<table class="generic">
<thead><tr class="qt-style"><th >Attribute</th><th >Presence</th><th >Values</th><th >Comment</th></tr></thead>
<tr valign="top" class="odd"><td ><tt>language</tt></td><td >optional</td><td >&quot;c++&quot;, &quot;jambi&quot;</td><td >This attribute specifies the language the custom widget is intended for. It is mainly there to prevent C++-plugins from appearing in Qt Jambi.</td></tr>
<tr valign="top" class="even"><td ><tt>displayname</tt></td><td >optional</td><td >Class name</td><td >The value of the attribute appears in the Widget box and can be used to strip away namespaces.</td></tr>
</table>
<p>The <tt>&lt;addpagemethod&gt;</tt> tag tells <i>Qt Designer</i> and <a href="uic.html#uic">uic</a> which method should be used to add pages to a container widget. This applies to container widgets that require calling a particular method to add a child rather than adding the child by passing the parent. In particular, this is relevant for containers that are not a a subclass of the containers provided in <i>Qt Designer</i>, but are based on the notion of <i>Current Page</i>. In addition, you need to provide a container extension for them.</p>
<p>The <tt>&lt;propertyspecifications&gt;</tt> element can contain a list of property meta information. Currently, properties of type string are supported. For these properties, the <tt>&lt;stringpropertyspecification&gt;</tt> tag can be used. This tag has the following attributes:</p>
<table class="generic">
<thead><tr class="qt-style"><th >Attribute</th><th >Presence</th><th >Values</th><th >Comment</th></tr></thead>
<tr valign="top" class="odd"><td ><tt>name</tt></td><td >required</td><td >Name of the property</td></tr>
<tr valign="top" class="even"><td ><tt>type</tt></td><td >required</td><td >See below table</td><td >The value of the attribute determines how the property editor will handle them.</td></tr>
<tr valign="top" class="odd"><td ><tt>notr</tt></td><td >optional</td><td >&quot;true&quot;, &quot;false&quot;</td><td >If the attribute is &quot;true&quot;, the value is not meant to be translated.</td></tr>
</table>
<p>Values of the <tt>type</tt> attribute of the string property:</p>
<table class="generic">
<thead><tr class="qt-style"><th >Value</th><th >Type</th></tr></thead>
<tr valign="top" class="odd"><td ><tt>&quot;richtext&quot;</tt></td><td >Rich text.</td></tr>
<tr valign="top" class="even"><td ><tt>&quot;multiline&quot;</tt></td><td >Multi-line plain text.</td></tr>
<tr valign="top" class="odd"><td ><tt>&quot;singleline&quot;</tt></td><td >Single-line plain text.</td></tr>
<tr valign="top" class="even"><td ><tt>&quot;stylesheet&quot;</tt></td><td >A CSS-style sheet.</td></tr>
<tr valign="top" class="odd"><td ><tt>&quot;objectname&quot;</tt></td><td >An object name (restricted set of valid characters).</td></tr>
<tr valign="top" class="even"><td ><tt>&quot;url&quot;</tt></td><td >URL, file name.</td></tr>
</table>
<a name="plugin-requirements"></a>
<h2>Plugin Requirements</h2>
<p>In order for plugins to work correctly on all platforms, you need to ensure that they export the symbols needed by <i>Qt Designer</i>.</p>
<p>First of all, the plugin class must be exported in order for the plugin to be loaded by <i>Qt Designer</i>. Use the <a href="qtplugin.html#Q_EXPORT_PLUGIN2">Q_EXPORT_PLUGIN2</a>() macro to do this. Also, the <a href="qdesignercustomwidgetinterface.html#QDESIGNER_WIDGET_EXPORT">QDESIGNER_WIDGET_EXPORT</a> macro must be used to define each custom widget class within a plugin, that <i>Qt Designer</i> will instantiate.</p>
<a name="creating-well-behaved-widgets"></a>
<h2>Creating Well Behaved Widgets</h2>
<p>Some custom widgets have special user interface features that may make them behave differently to many of the standard widgets found in <i>Qt Designer</i>. Specifically, if a custom widget grabs the keyboard as a result of a call to <a href="qwidget.html#grabKeyboard">QWidget::grabKeyboard</a>(), the operation of <i>Qt Designer</i> will be affected.</p>
<p>To give custom widgets special behavior in <i>Qt Designer</i>, provide an implementation of the initialize() function to configure the widget construction process for <i>Qt Designer</i> specific behavior. This function will be called for the first time before any calls to createWidget() and could perhaps set an internal flag that can be tested later when <i>Qt Designer</i> calls the plugin's createWidget() function.</p>
<a name="buildingandinstallingtheplugin"></a><a name="building-and-installing-the-plugin"></a>
<h2>Building and Installing the Plugin</h2>
<a name="a-simple-plugin"></a>
<h3>A Simple Plugin</h3>
<p>The <a href="designer-customwidgetplugin.html">Custom Widget Plugin Example</a> demonstrates a simple <i>Qt Designer</i> plugin.</p>
<p>The <tt>.pro</tt> file for a plugin must specify the headers and sources for both the custom widget and the plugin interface. Typically, this file only has to specify that the plugin's project is to be built as a library, but with specific plugin support for <i>Qt Designer</i>. This is done with the following declarations:</p>
<pre class="cpp"> CONFIG      += designer plugin
 TARGET      = $$qtLibraryTarget($$TARGET)
 TEMPLATE    = lib</pre>
<p>If Qt is configured to build in both debug and release modes, <i>Qt Designer</i> will be built in release mode. When this occurs, it is necessary to ensure that plugins are also built in release mode. To do this, include the following declaration in the plugin's <tt>.pro</tt> file:</p>
<pre class="cpp"> CONFIG += release</pre>
<p>If plugins are built in a mode that is incompatible with <i>Qt Designer</i>, they will not be loaded and installed. For more information about plugins, see the <a href="plugins-howto.html">Plugins HOWTO</a> document.</p>
<p>It is also necessary to ensure that the plugin is installed together with other <i>Qt Designer</i> widget plugins:</p>
<pre class="cpp"> target.path = $$[QT_INSTALL_PLUGINS]/designer
 INSTALLS += target</pre>
<p>The <tt>$[QT_INSTALL_PLUGINS]</tt> variable is a placeholder to the location of the installed Qt plugins. You can configure <i>Qt Designer</i> to look for plugins in other locations by setting the <tt>QT_PLUGIN_PATH</tt> environment variable before running the application.</p>
<p><b>Note:</b> <i>Qt Designer</i> will look for a <tt>designer</tt> subdirectory in each path supplied.</p>
<p>See <a href="qcoreapplication.html#libraryPaths">QCoreApplication::libraryPaths</a>() for more information about customizing paths for libraries and plugins with Qt applications.</p>
<a name="splitting-up-the-plugin"></a>
<h3>Splitting up the Plugin</h3>
<p>In a real world scenario, you do not want to have dependencies of the application making use of the custom widgets to the <i>Qt Designer</i> headers and libraries as introduced by the simple approach explained above.</p>
<p>There are two ways to resolve this:</p>
<ul>
<li>Create a <tt>.pri</tt> file that contains the headers sources and sources of the custom widget:<pre class="cpp">            INCLUDEPATH <span class="operator">+</span><span class="operator">=</span> $$PWD
            HEADERS <span class="operator">+</span><span class="operator">=</span> $$PWD<span class="operator">/</span>analogclock<span class="operator">.</span>h
            SOURCES <span class="operator">+</span><span class="operator">=</span> $$PWD<span class="operator">/</span>analogclock<span class="operator">.</span>cpp</pre>
<p>This file would then be included by the <tt>.pro</tt> file of the plugin and the application:</p>
<pre class="cpp">            <span class="keyword">include</span>(customwidget<span class="operator">.</span>pri)</pre>
<p>Running <tt>qmake -Wall</tt> on the <tt>.pro</tt> files causes a warning to be printed if an included <tt>.pri</tt> file cannot be found.</p>
</li>
<li>Create a standalone shared library containing the custom widgets only as described in <a href="sharedlibrary.html">Creating Shared Libraries</a>.<p>This library would then be used by the application as well as by the <i>Qt Designer</i> plugin. Care must be taken to ensure that the plugin can locate the library at run-time.</p>
</li>
</ul>
<a name="related-examples"></a>
<h2>Related Examples</h2>
<p>For more information on using custom widgets in <i>Qt Designer</i>, refer to the <a href="designer-customwidgetplugin.html">Custom Widget Plugin</a> and <a href="designer-worldtimeclockplugin.html">World Time Clock Plugin</a> examples for more information about using custom widgets in <i>Qt Designer</i>. Also, you can use the <a href="qdesignercustomwidgetcollectioninterface.html">QDesignerCustomWidgetCollectionInterface</a> class to combine several custom widgets into a single library.</p>
</div>
<!-- @@@designer-creating-custom-widgets.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="designer-using-custom-widgets.html">Using Custom Widgets with Qt Designer</a>
<a class="nextPage" href="designer-creating-custom-widgets-extensions.html">Creating Custom Widget Extensions</a>
</p>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
      Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Qt and respective logos are trademarks of The Qt Company Ltd 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>