Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 1458

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" />
<!-- containerextension.qdoc -->
  <title>Qt 4.8: Container Extension Example</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><a href="all-examples.html">Examples</a></li>
<li>Container Extension Example</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">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#the-project-file-containerextension-pro">The Project File: containerextension.pro</a></li>
<li class="level1"><a href="#multipagewidgetplugin-class-definition">MultiPageWidgetPlugin Class Definition</a></li>
<li class="level1"><a href="#multipagewidgetplugin-class-implementation">MultiPageWidgetPlugin Class Implementation</a></li>
<li class="level1"><a href="#multipagewidgetextensionfactory-class-definition">MultiPageWidgetExtensionFactory Class Definition</a></li>
<li class="level1"><a href="#multipagewidgetextensionfactory-class-implementation">MultiPageWidgetExtensionFactory Class Implementation</a></li>
<li class="level1"><a href="#multipagewidgetcontainerextension-class-definition">MultiPageWidgetContainerExtension Class Definition</a></li>
<li class="level1"><a href="#multipagewidgetcontainerextension-class-implementation">MultiPageWidgetContainerExtension Class Implementation</a></li>
<li class="level1"><a href="#multipagewidget-class-definition">MultiPageWidget Class Definition</a></li>
</ul>
</div>
<h1 class="title">Container Extension Example</h1>
<span class="subtitle"></span>
<!-- $$$designer/containerextension-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="designer-containerextension-multipagewidget-cpp.html">designer/containerextension/multipagewidget.cpp</a></li>
<li><a href="designer-containerextension-multipagewidget-h.html">designer/containerextension/multipagewidget.h</a></li>
<li><a href="designer-containerextension-multipagewidgetcontainerextension-cpp.html">designer/containerextension/multipagewidgetcontainerextension.cpp</a></li>
<li><a href="designer-containerextension-multipagewidgetcontainerextension-h.html">designer/containerextension/multipagewidgetcontainerextension.h</a></li>
<li><a href="designer-containerextension-multipagewidgetextensionfactory-cpp.html">designer/containerextension/multipagewidgetextensionfactory.cpp</a></li>
<li><a href="designer-containerextension-multipagewidgetextensionfactory-h.html">designer/containerextension/multipagewidgetextensionfactory.h</a></li>
<li><a href="designer-containerextension-multipagewidgetplugin-cpp.html">designer/containerextension/multipagewidgetplugin.cpp</a></li>
<li><a href="designer-containerextension-multipagewidgetplugin-h.html">designer/containerextension/multipagewidgetplugin.h</a></li>
<li><a href="designer-containerextension-containerextension-pro.html">designer/containerextension/containerextension.pro</a></li>
</ul>
<p>The Container Extension example shows how to create a custom multi-page plugin for Qt Designer using the <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a> class.<p class="centerAlign"><img src="images/containerextension-example.png" alt="" /></p><p>To provide a custom widget that can be used with <i>Qt Designer</i>, we need to supply a self-contained implementation. In this example we use a custom multi-page widget designed to show the container extension feature.</p>
<p>An extension is an object which modifies the behavior of <i>Qt Designer</i>. The <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a> enables <i>Qt Designer</i> to manage and manipulate a custom multi-page widget, i.e&#x2e; adding and deleting pages to the widget.</p>
<p>There are four available types of extensions in <i>Qt Designer</i>:</p>
<ul>
<li><a href="qdesignermembersheetextension.html">QDesignerMemberSheetExtension</a> provides an extension that allows you to manipulate a widget's member functions which is displayed when configuring connections using Qt Designer's mode for editing signals and slots.</li>
<li><a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a> provides an extension that allows you to manipulate a widget's properties which is displayed in Qt Designer's property editor.</li>
<li><a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a> provides an extension that allows you to add custom menu entries to <i>Qt Designer</i>'s task menu.</li>
<li><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a> provides an extension that allows you to add (and delete) pages to a multi-page container plugin in <i>Qt Designer</i>.</li>
</ul>
<p>You can use all the extensions following the same pattern as in this example, only replacing the respective extension base class. For more information, see the <a href="qtdesigner.html">QtDesigner Module</a>.</p>
<p>The Container Extension example consists of four classes:</p>
<ul>
<li><tt>MultiPageWidget</tt> is a custom container widget that lets the user manipulate and populate its pages, and navigate among these using a combobox.</li>
<li><tt>MultiPageWidgetPlugin</tt> exposes the <tt>MultiPageWidget</tt> class to <i>Qt Designer</i>.</li>
<li><tt>MultiPageWidgetExtensionFactory</tt> creates a <tt>MultiPageWidgetContainerExtension</tt> object.</li>
<li><tt>MultiPageWidgetContainerExtension</tt> provides the container extension.</li>
</ul>
<p>The project file for custom widget plugins needs some additional information to ensure that they will work within <i>Qt Designer</i>. For example, custom widget plugins rely on components supplied with <i>Qt Designer</i>, and this must be specified in the project file that we use. We will first take a look at the plugin's project file.</p>
<p>Then we will continue by reviewing the <tt>MultiPageWidgetPlugin</tt> class, and take a look at the <tt>MultiPageWidgetExtensionFactory</tt> and <tt>MultiPageWidgetContainerExtension</tt> classes. Finally, we will take a quick look at the <tt>MultiPageWidget</tt> class definition.</p>
<a name="the-project-file-containerextension-pro"></a>
<h2>The Project File: containerextension.pro</h2>
<p>The project file must contain some additional information to ensure that the plugin will work as expected:</p>
<pre class="cpp"> TEMPLATE = lib
 CONFIG  += designer plugin</pre>
<p>The <tt>TEMPLATE</tt> variable's value makes <tt>qmake</tt> create the custom widget as a library. Later, we will ensure that the widget will be recognized as a plugin by Qt by using the <a href="qtplugin.html#Q_EXPORT_PLUGIN2">Q_EXPORT_PLUGIN2</a>() macro to export the relevant widget information.</p>
<p>The <tt>CONFIG</tt> variable contains two values, <tt>designer</tt> and <tt>plugin</tt>:</p>
<ul>
<li><tt>designer</tt>: Since custom widgets plugins rely on components supplied with <i>Qt Designer</i>, this value ensures that our plugin links against <i>Qt Designer</i>'s library (<tt>libQtDesigner.so</tt>).</li>
<li><tt>plugin</tt>: We also need to ensure that <tt>qmake</tt> considers the custom widget a <i>plugin</i> library.</li>
</ul>
<p>When 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. For that reason we add a <tt>debug_and_release</tt> value to the <tt>CONFIG</tt> variable. Otherwise, if a plugin is built in a mode that is incompatible with <i>Qt Designer</i>, it won't be loaded and installed.</p>
<p>The header and source files for the widget are declared in the usual way:</p>
<pre class="cpp"> HEADERS += multipagewidget.h \
            multipagewidgetplugin.h \
            multipagewidgetcontainerextension.h \
            multipagewidgetextensionfactory.h

 SOURCES += multipagewidget.cpp \
            multipagewidgetplugin.cpp \
            multipagewidgetcontainerextension.cpp \
            multipagewidgetextensionfactory.cpp</pre>
<p>We provide an implementation of the plugin interface so that <i>Qt Designer</i> can use the custom widget. In this particular example we also provide implementations of the container extension interface and the extension factory.</p>
<p>It is important to ensure that the plugin is installed in a location that is searched by <i>Qt Designer</i>. We do this by specifying a target path for the project and adding it to the list of items to install:</p>
<pre class="cpp"> target.path = $$[QT_INSTALL_PLUGINS]/designer
 INSTALLS += target</pre>
<p>The container extension is created as a library, and will be installed alongside the other <i>Qt Designer</i> plugins when the project is installed (using <tt>make install</tt> or an equivalent installation procedure).</p>
<p>Note that if you want the plugins to appear in a Visual Studio integration, the plugins must be built in release mode and their libraries must be copied into the plugin directory in the install path of the integration (for an example, see <tt>C:/program files/trolltech as/visual studio integration/plugins</tt>).</p>
<p>For more information about plugins, see the <a href="plugins-howto.html">How to Create Qt Plugins</a> documentation.</p>
<a name="multipagewidgetplugin-class-definition"></a>
<h2>MultiPageWidgetPlugin Class Definition</h2>
<p>The <tt>MultiPageWidgetPlugin</tt> class exposes the <tt>MultiPageWidget</tt> class to <i>Qt Designer</i>. Its definition is similar to the <a href="designer-customwidgetplugin.html">Custom Widget Plugin</a> example's plugin class which is explained in detail. The parts of the class definition that is specific to this particular custom widget is the class name and a couple of private slots:</p>
<pre class="cpp"> <span class="preprocessor">#ifndef MULTIPAGEWIDGETPLUGIN_H</span>
 <span class="preprocessor">#define MULTIPAGEWIDGETPLUGIN_H</span>

 <span class="preprocessor">#include &lt;QtDesigner/QDesignerCustomWidgetInterface&gt;</span>

 <span class="keyword">class</span> <span class="type"><a href="qicon.html">QIcon</a></span>;
 <span class="keyword">class</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;

 <span class="keyword">class</span> MultiPageWidgetPlugin: <span class="keyword">public</span> <span class="type"><a href="qobject.html">QObject</a></span><span class="operator">,</span> <span class="keyword">public</span> <span class="type"><a href="qdesignercustomwidgetinterface.html">QDesignerCustomWidgetInterface</a></span>
 {
     Q_OBJECT
     Q_INTERFACES(<span class="type"><a href="qdesignercustomwidgetinterface.html">QDesignerCustomWidgetInterface</a></span>)
 <span class="keyword">public</span>:
     MultiPageWidgetPlugin(<span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>);

     <span class="type"><a href="qstring.html">QString</a></span> name() <span class="keyword">const</span>;
     <span class="type"><a href="qstring.html">QString</a></span> group() <span class="keyword">const</span>;
     <span class="type"><a href="qstring.html">QString</a></span> toolTip() <span class="keyword">const</span>;
     <span class="type"><a href="qstring.html">QString</a></span> whatsThis() <span class="keyword">const</span>;
     <span class="type"><a href="qstring.html">QString</a></span> includeFile() <span class="keyword">const</span>;
     <span class="type"><a href="qicon.html">QIcon</a></span> icon() <span class="keyword">const</span>;
     <span class="type">bool</span> isContainer() <span class="keyword">const</span>;
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>createWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent);
     <span class="type">bool</span> isInitialized() <span class="keyword">const</span>;
     <span class="type">void</span> initialize(<span class="type"><a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a></span> <span class="operator">*</span>formEditor);
     <span class="type"><a href="qstring.html">QString</a></span> domXml() <span class="keyword">const</span>;

 <span class="keyword">private</span> <span class="keyword">slots</span>:
     <span class="type">void</span> currentIndexChanged(<span class="type">int</span> index);
     <span class="type">void</span> pageTitleChanged(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>title);

 <span class="keyword">private</span>:
     <span class="type">bool</span> initialized;
 };

 <span class="preprocessor">#endif</span></pre>
<p>The plugin class provides <i>Qt Designer</i> with basic information about our plugin, such as its class name and its include file. Furthermore it knows how to create instances of the <tt>MultiPageWidget</tt> widget. <tt>MultiPageWidgetPlugin</tt> also defines the <a href="qdesignercustomwidgetinterface.html#initialize">initialize()</a> function which is called after the plugin is loaded into <i>Qt Designer</i>. The function's <a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a> parameter provides the plugin with a gateway to all of <i>Qt Designer</i>'s API's.</p>
<p>In the case of a multipage widget such as ours, we must also implement two private slots, currentIndexChanged() and pageTitleChanged(), to be able to update <i>Qt Designer</i>'s property editor whenever the user views another page or changes one of the page titles. To be able to give each page their own title, we have chosen to use the <a href="qwidget.html#windowTitle-prop">QWidget::windowTitle</a> property to store the page title (for more information see the MultiPageWidget class <a href="designer-containerextension-multipagewidget-cpp.html">implementation</a>). Note that currently there is no way of adding a custom property (e.g&#x2e;, a page title) to the pages without using a predefined property as placeholder.</p>
<p>The <tt>MultiPageWidgetPlugin</tt> class inherits from both <a href="qobject.html">QObject</a> and <a href="qdesignercustomwidgetinterface.html">QDesignerCustomWidgetInterface</a>. It is important to remember, when using multiple inheritance, to ensure that all the interfaces (i.e&#x2e; the classes that doesn't inherit <a href="qobject.html#Q_OBJECT">Q_OBJECT</a>) are made known to the meta object system using the <a href="qobject.html#Q_INTERFACES">Q_INTERFACES</a>() macro. This enables <i>Qt Designer</i> to use <a href="qobject.html#qobject_cast">qobject_cast</a>() to query for supported interfaces using nothing but a <a href="qobject.html">QObject</a> pointer.</p>
<a name="multipagewidgetplugin-class-implementation"></a>
<h2>MultiPageWidgetPlugin Class Implementation</h2>
<p>The MultiPageWidgetPlugin class implementation is in most parts equivalent to the <a href="designer-customwidgetplugin.html">Custom Widget Plugin</a> example's plugin class:</p>
<pre class="cpp"> MultiPageWidgetPlugin<span class="operator">::</span>MultiPageWidgetPlugin(<span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent)
     :<span class="type"><a href="qobject.html">QObject</a></span>(parent)
 {
     initialized <span class="operator">=</span> <span class="keyword">false</span>;
 }

 <span class="type"><a href="qstring.html">QString</a></span> MultiPageWidgetPlugin<span class="operator">::</span>name() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> QLatin1String(<span class="string">&quot;MultiPageWidget&quot;</span>);
 }

 <span class="type"><a href="qstring.html">QString</a></span> MultiPageWidgetPlugin<span class="operator">::</span>group() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> QLatin1String(<span class="string">&quot;Display Widgets [Examples]&quot;</span>);
 }

 <span class="type"><a href="qstring.html">QString</a></span> MultiPageWidgetPlugin<span class="operator">::</span>toolTip() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> <span class="type"><a href="qstring.html">QString</a></span>();
 }

 <span class="type"><a href="qstring.html">QString</a></span> MultiPageWidgetPlugin<span class="operator">::</span>whatsThis() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> <span class="type"><a href="qstring.html">QString</a></span>();
 }

 <span class="type"><a href="qstring.html">QString</a></span> MultiPageWidgetPlugin<span class="operator">::</span>includeFile() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> QLatin1String(<span class="string">&quot;multipagewidget.h&quot;</span>);
 }

 <span class="type"><a href="qicon.html">QIcon</a></span> MultiPageWidgetPlugin<span class="operator">::</span>icon() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> <span class="type"><a href="qicon.html">QIcon</a></span>();
 }

 <span class="type">bool</span> MultiPageWidgetPlugin<span class="operator">::</span>isInitialized() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> initialized;
 }</pre>
<p>One of the functions that differ is the isContainer() function which returns true in this example since our custom widget is intended to be used as a container.</p>
<pre class="cpp"> <span class="type">bool</span> MultiPageWidgetPlugin<span class="operator">::</span>isContainer() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> <span class="keyword">true</span>;
 }</pre>
<p>Another function that differ is the function creating our custom widget:</p>
<pre class="cpp"> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>MultiPageWidgetPlugin<span class="operator">::</span>createWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
 {
     MultiPageWidget <span class="operator">*</span>widget <span class="operator">=</span> <span class="keyword">new</span> MultiPageWidget(parent);
     connect(widget<span class="operator">,</span> SIGNAL(currentIndexChanged(<span class="type">int</span>))<span class="operator">,</span>
             <span class="keyword">this</span><span class="operator">,</span> SLOT(currentIndexChanged(<span class="type">int</span>)));
     connect(widget<span class="operator">,</span> SIGNAL(pageTitleChanged(<span class="type"><a href="qstring.html">QString</a></span>))<span class="operator">,</span>
             <span class="keyword">this</span><span class="operator">,</span> SLOT(pageTitleChanged(<span class="type"><a href="qstring.html">QString</a></span>)));
     <span class="keyword">return</span> widget;
 }</pre>
<p>In addition to create and return the widget, we connect our custom container widget's currentIndexChanged() signal to the plugin's currentIndexChanged() slot to ensure that <i>Qt Designer</i>'s property editor is updated whenever the user views another page. We also connect the widget's pageTitleChanged() signal to the plugin's pageTitleChanged() slot.</p>
<p>The currentIndexChanged() slot is called whenever our custom widget's currentIndexChanged() <i>signal</i> is emitted, i.e&#x2e; whenever the user views another page:</p>
<pre class="cpp"> <span class="type">void</span> MultiPageWidgetPlugin<span class="operator">::</span>currentIndexChanged(<span class="type">int</span> index)
 {
     Q_UNUSED(index);
     MultiPageWidget <span class="operator">*</span>widget <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>MultiPageWidget<span class="operator">*</span><span class="operator">&gt;</span>(sender());</pre>
<p>First, we retrieve the object emitting the signal using the <a href="qobject.html#sender">QObject::sender</a>() and <a href="qobject.html#qobject_cast">qobject_cast</a>() functions. If it's called in a slot activated by a signal, <a href="qobject.html#sender">QObject::sender</a>() returns a pointer to the object that sent the signal; otherwise it returns 0.</p>
<pre class="cpp">     <span class="keyword">if</span> (widget) {
         <span class="type"><a href="qdesignerformwindowinterface.html">QDesignerFormWindowInterface</a></span> <span class="operator">*</span>form <span class="operator">=</span> <span class="type"><a href="qdesignerformwindowinterface.html">QDesignerFormWindowInterface</a></span><span class="operator">::</span>findFormWindow(widget);
         <span class="keyword">if</span> (form)
             form<span class="operator">-</span><span class="operator">&gt;</span>emitSelectionChanged();
     }
 }</pre>
<p>Once we have the widget we can update the property editor. <i>Qt Designer</i> uses the <a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a> class to feed its property editor, and whenever a widget is selected in its workspace, Qt Designer will query for the widget's property sheet extension and update the property editor.</p>
<p>So what we want to achieve is to notify <i>Qt Designer</i> that our widget's <i>internal</i> selection has changed: First we use the static <a href="qdesignerformwindowinterface.html#findFormWindow">QDesignerFormWindowInterface::findFormWindow</a>() function to retrieve the <a href="qdesignerformwindowinterface.html">QDesignerFormWindowInterface</a> object containing the widget. The <a href="qdesignerformwindowinterface.html">QDesignerFormWindowInterface</a> class allows you to query and manipulate form windows appearing in Qt Designer's workspace. Then, all we have to do is to emit its <a href="qdesignerformwindowinterface.html#emitSelectionChanged">emitSelectionChanged()</a> signal, forcing an update of the property editor.</p>
<p>When changing a page title a generic refresh of the property editor is not enough because it is actually the page's property extension that needs to be updated. For that reason we need to access the <a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a> object for the page which title we want to change. The <a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a> class also allows you to manipulate a widget's properties, but to get hold of the extension we must first retrieve access to <i>Qt Designer</i>'s extension manager:</p>
<pre class="cpp"> <span class="type">void</span> MultiPageWidgetPlugin<span class="operator">::</span>pageTitleChanged(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>title)
 {
     Q_UNUSED(title);
     MultiPageWidget <span class="operator">*</span>widget <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>MultiPageWidget<span class="operator">*</span><span class="operator">&gt;</span>(sender());
     <span class="keyword">if</span> (widget) {
         <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>page <span class="operator">=</span> widget<span class="operator">-</span><span class="operator">&gt;</span>widget(widget<span class="operator">-</span><span class="operator">&gt;</span>currentIndex());
         <span class="type"><a href="qdesignerformwindowinterface.html">QDesignerFormWindowInterface</a></span> <span class="operator">*</span>form;
         form <span class="operator">=</span> <span class="type"><a href="qdesignerformwindowinterface.html">QDesignerFormWindowInterface</a></span><span class="operator">::</span>findFormWindow(widget);</pre>
<p>Again we first retrieve the widget emitting the signal, using the <a href="qobject.html#sender">QObject::sender</a>() and <a href="qobject.html#qobject_cast">qobject_cast</a>() functions. Then we retrieve the current page from the widget that emitted the signal, and we use the static <a href="qdesignerformwindowinterface.html#findFormWindow">QDesignerFormWindowInterface::findFormWindow</a>() function to retrieve the form containing our widget.</p>
<pre class="cpp">             <span class="type"><a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a></span> <span class="operator">*</span>editor <span class="operator">=</span> form<span class="operator">-</span><span class="operator">&gt;</span>core();
             <span class="type"><a href="qextensionmanager.html">QExtensionManager</a></span> <span class="operator">*</span>manager <span class="operator">=</span> editor<span class="operator">-</span><span class="operator">&gt;</span>extensionManager();</pre>
<p>Now that we have the form window, the <a href="qdesignerformwindowinterface.html">QDesignerFormWindowInterface</a> class provides the <a href="qdesignerformwindowinterface.html#core">core()</a> function which returns the current <a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a> object. The <a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a> class allows you to access Qt Designer's various components. In particular, the <a href="qdesignerformeditorinterface.html#extensionManager">QDesignerFormEditorInterface::extensionManager</a>() function returns a reference to the current extension manager.</p>
<pre class="cpp">             <span class="type"><a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a></span> <span class="operator">*</span>sheet;
             sheet <span class="operator">=</span> qt_extension<span class="operator">&lt;</span><span class="type"><a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a></span><span class="operator">*</span><span class="operator">&gt;</span>(manager<span class="operator">,</span> page);
             <span class="keyword">const</span> <span class="type">int</span> propertyIndex <span class="operator">=</span> sheet<span class="operator">-</span><span class="operator">&gt;</span>indexOf(QLatin1String(<span class="string">&quot;windowTitle&quot;</span>));
             sheet<span class="operator">-</span><span class="operator">&gt;</span>setChanged(propertyIndex<span class="operator">,</span> <span class="keyword">true</span>);
         }
     }
 }</pre>
<p>Once we have the extension manager we can update the extension sheet: First we retrieve the property extension for the page which title we want to change, using the <a href="qextensionmanager.html#qt_extension">qt_extension</a>() function. Then we retrieve the index for the page title using the <a href="qdesignerpropertysheetextension.html#indexOf">QDesignerPropertySheetExtension::indexOf</a>() function. As previously mentioned, we have chosen to use the <a href="qwidget.html#windowTitle-prop">QWidget::windowTitle</a> property to store the page title (for more information see the MultiPageWidget class <a href="designer-containerextension-multipagewidget-cpp.html">implementation</a>). Finally, we implicitly force an update of the page's property sheet by calling the <a href="qdesignerpropertysheetextension.html#setChanged">QDesignerPropertySheetExtension::setChanged</a>() function.</p>
<pre class="cpp"> <span class="type">void</span> MultiPageWidgetPlugin<span class="operator">::</span>initialize(<span class="type"><a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a></span> <span class="operator">*</span>formEditor)
 {
     <span class="keyword">if</span> (initialized)
         <span class="keyword">return</span>;</pre>
<p>Note also the initialize() function: The <tt>initialize()</tt> function takes a <a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a> object as argument.</p>
<pre class="cpp">     <span class="type"><a href="qextensionmanager.html">QExtensionManager</a></span> <span class="operator">*</span>manager <span class="operator">=</span> formEditor<span class="operator">-</span><span class="operator">&gt;</span>extensionManager();</pre>
<p>When creating extensions associated with custom widget plugins, we need to access <i>Qt Designer</i>'s current extension manager which we retrieve from the <a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a> parameter.</p>
<p>In addition to allowing you to manipulate a widget's properties, the <a href="qextensionmanager.html">QExtensionManager</a> class provides extension management facilities for <i>Qt Designer</i>. Using <i>Qt Designer</i>'s current extension manager you can retrieve the extension for a given object. You can also register and unregister an extension for a given object. Remember that an extension is an object which modifies the behavior of <i>Qt Designer</i>.</p>
<p>When registrering an extension, it is actually the associated extension factory that is registered. In <i>Qt Designer</i>, extension factories are used to look up and create named extensions as they are required. So, in this example, the container extension itself is not created until <i>Qt Designer</i> must know whether the associated widget is a container, or not.</p>
<pre class="cpp">     <span class="type"><a href="qextensionfactory.html">QExtensionFactory</a></span> <span class="operator">*</span>factory <span class="operator">=</span> <span class="keyword">new</span> MultiPageWidgetExtensionFactory(manager);

     Q_ASSERT(manager <span class="operator">!</span><span class="operator">=</span> <span class="number">0</span>);
     manager<span class="operator">-</span><span class="operator">&gt;</span>registerExtensions(factory<span class="operator">,</span> Q_TYPEID(<span class="type"><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a></span>));

     initialized <span class="operator">=</span> <span class="keyword">true</span>;
 }</pre>
<p>We create a <tt>MultiPageWidgetExtensionFactory</tt> object that we register using <i>Qt Designer</i>'s current <a href="qextensionmanager.html">extension manager</a> retrieved from the <a href="qdesignerformeditorinterface.html">QDesignerFormEditorInterface</a> parameter. The first argument is the newly created factory and the second argument is an extension identifier which is a string. The <tt>Q_TYPEID()</tt> macro simply convert the string into a <a href="qlatin1string.html">QLatin1String</a>.</p>
<p>The <tt>MultiPageWidgetExtensionFactory</tt> class is a subclass of <a href="qextensionfactory.html">QExtensionFactory</a>. When <i>Qt Designer</i> must know whether a widget is a container, or not, <i>Qt Designer</i>'s extension manager will run through all its registered factories invoking the first one which is able to create a container extension for that widget. This factory will in turn create a <tt>MultiPageWidgetExtension</tt> object.</p>
<pre class="cpp"> <span class="type"><a href="qstring.html">QString</a></span> MultiPageWidgetPlugin<span class="operator">::</span>domXml() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> QLatin1String(<span class="string">&quot;\
 &lt;ui language=\&quot;c++\&quot;&gt;\
     &lt;widget class=\&quot;MultiPageWidget\&quot; name=\&quot;multipagewidget\&quot;&gt;\
         &lt;widget class=\&quot;QWidget\&quot; name=\&quot;page\&quot; /&gt;\
     &lt;/widget&gt;\
     &lt;customwidgets&gt;\
         &lt;customwidget&gt;\
             &lt;class&gt;MultiPageWidget&lt;/class&gt;\
             &lt;extends&gt;QWidget&lt;/extends&gt;\
             &lt;addpagemethod&gt;addPage&lt;/addpagemethod&gt;\
         &lt;/customwidget&gt;\
     &lt;/customwidgets&gt;\
 &lt;/ui&gt;&quot;</span>);
 }</pre>
<p>Finally, take a look at the <tt>domXml()</tt> function. This function includes default settings for the widget in the standard XML format used by <i>Qt Designer</i>. In this case, we specify the container's first page; any inital pages of a multi-page widget must be specified within this function.</p>
<pre class="cpp"> <a href="qtplugin.html#Q_EXPORT_PLUGIN2">Q_EXPORT_PLUGIN2</a>(containerextension<span class="operator">,</span> MultiPageWidgetPlugin)</pre>
<p>Remember to use the <a href="qtplugin.html#Q_EXPORT_PLUGIN2">Q_EXPORT_PLUGIN2</a>() macro to export the MultiPageWidgetPlugin class for use with Qt's plugin handling classes: This macro ensures that <i>Qt Designer</i> can access and construct the custom widget. Without this macro, there is no way for <i>Qt Designer</i> to use the widget.</p>
<a name="multipagewidgetextensionfactory-class-definition"></a>
<h2>MultiPageWidgetExtensionFactory Class Definition</h2>
<p>The <tt>MultiPageWidgetExtensionFactory</tt> class inherits <a href="qextensionfactory.html">QExtensionFactory</a> which provides a standard extension factory for <i>Qt Designer</i>.</p>
<pre class="cpp"> <span class="keyword">class</span> MultiPageWidgetExtensionFactory: <span class="keyword">public</span> <span class="type"><a href="qextensionfactory.html">QExtensionFactory</a></span>
 {
     Q_OBJECT

 <span class="keyword">public</span>:
     MultiPageWidgetExtensionFactory(<span class="type"><a href="qextensionmanager.html">QExtensionManager</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>);

 <span class="keyword">protected</span>:
     <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>createExtension(<span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>object<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>iid<span class="operator">,</span> <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent) <span class="keyword">const</span>;
 };</pre>
<p>The subclass's purpose is to reimplement the <a href="qextensionfactory.html#createExtension">QExtensionFactory::createExtension</a>() function, making it able to create a <tt>MultiPageWidget</tt> container extension.</p>
<a name="multipagewidgetextensionfactory-class-implementation"></a>
<h2>MultiPageWidgetExtensionFactory Class Implementation</h2>
<p>The class constructor simply calls the <a href="qextensionfactory.html">QExtensionFactory</a> base class constructor:</p>
<pre class="cpp"> MultiPageWidgetExtensionFactory<span class="operator">::</span>MultiPageWidgetExtensionFactory(<span class="type"><a href="qextensionmanager.html">QExtensionManager</a></span> <span class="operator">*</span>parent)
     : <span class="type"><a href="qextensionfactory.html">QExtensionFactory</a></span>(parent)
 {}</pre>
<p>As described above, the factory is invoked when <i>Qt Designer</i> must know whether the associated widget is a container, or not.</p>
<pre class="cpp"> <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>MultiPageWidgetExtensionFactory<span class="operator">::</span>createExtension(<span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>object<span class="operator">,</span>
                                                           <span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>iid<span class="operator">,</span>
                                                           <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent) <span class="keyword">const</span>
 {
     MultiPageWidget <span class="operator">*</span>widget <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>MultiPageWidget<span class="operator">*</span><span class="operator">&gt;</span>(object);

     <span class="keyword">if</span> (widget <span class="operator">&amp;</span><span class="operator">&amp;</span> (iid <span class="operator">=</span><span class="operator">=</span> Q_TYPEID(<span class="type"><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a></span>))) {
         <span class="keyword">return</span> <span class="keyword">new</span> MultiPageWidgetContainerExtension(widget<span class="operator">,</span> parent);
     } <span class="keyword">else</span> {
         <span class="keyword">return</span> <span class="number">0</span>;
     }
 }</pre>
<p><i>Qt Designer</i>'s behavior is the same whether the requested extension is associated with a container, a member sheet, a property sheet or a task menu: Its extension manager runs through all its registered extension factories calling <tt>createExtension()</tt> for each until one responds by creating the requested extension.</p>
<p>So the first thing we do in <tt>MultiPageWidgetExtensionFactory::createExtension()</tt> is to check if the <a href="qobject.html">QObject</a>, for which the extension is requested, is in fact a <tt>MultiPageWidget</tt> object. Then we check if the requested extension is a container extension.</p>
<p>If the object is a MultiPageWidget requesting a container extension, we create and return a <tt>MultiPageWidgetExtension</tt> object. Otherwise, we simply return a null pointer, allowing <i>Qt Designer</i>'s extension manager to continue its search through the registered factories.</p>
<a name="multipagewidgetcontainerextension-class-definition"></a>
<h2>MultiPageWidgetContainerExtension Class Definition</h2>
<p>The <tt>MultiPageWidgetContainerExtension</tt> class inherits <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a> which allows you to add (and delete) pages to a multi-page container plugin in <i>Qt Designer</i>.</p>
<pre class="cpp"> <span class="keyword">class</span> MultiPageWidgetContainerExtension: <span class="keyword">public</span> <span class="type"><a href="qobject.html">QObject</a></span><span class="operator">,</span>
                                          <span class="keyword">public</span> <span class="type"><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a></span>
 {
     Q_OBJECT
     Q_INTERFACES(<span class="type"><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a></span>)

 <span class="keyword">public</span>:
     MultiPageWidgetContainerExtension(MultiPageWidget <span class="operator">*</span>widget<span class="operator">,</span> <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent);

     <span class="type">void</span> addWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget);
     <span class="type">int</span> count() <span class="keyword">const</span>;
     <span class="type">int</span> currentIndex() <span class="keyword">const</span>;
     <span class="type">void</span> insertWidget(<span class="type">int</span> index<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget);
     <span class="type">void</span> remove(<span class="type">int</span> index);
     <span class="type">void</span> setCurrentIndex(<span class="type">int</span> index);
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget(<span class="type">int</span> index) <span class="keyword">const</span>;

 <span class="keyword">private</span>:
     MultiPageWidget <span class="operator">*</span>myWidget;
 };</pre>
<p>It is important to recognize that the <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a> class only is intended to provide <i>Qt Designer</i> access to your custom multi-page widget's functionality; your custom multi-page widget must implement functionality corresponding to the extension's functions.</p>
<p>Note also that we implement a constructor that takes <i>two</i> arguments: the parent widget, and the <tt>MultiPageWidget</tt> object for which the task menu is requested.</p>
<p><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a> provides a couple of menu entries in <i>Qt Designer</i>'s task menu by default, enabling the user to add or delete pages to the associated custom multi-page widget in <i>Qt Designer</i>'s workspace.</p>
<a name="multipagewidgetcontainerextension-class-implementation"></a>
<h2>MultiPageWidgetContainerExtension Class Implementation</h2>
<p>In the constructor we save the reference to the <tt>MultiPageWidget</tt> object sent as parameter, i.e the widget associated with the extension. We will need this later to access the custom multi-page widget performing the requested actions.</p>
<pre class="cpp"> MultiPageWidgetContainerExtension<span class="operator">::</span>MultiPageWidgetContainerExtension(MultiPageWidget <span class="operator">*</span>widget<span class="operator">,</span>
                                                                      <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent)
     :<span class="type"><a href="qobject.html">QObject</a></span>(parent)
 {
     myWidget <span class="operator">=</span> widget;
 }</pre>
<p>To fully enable <i>Qt Designer</i> to manage and manipulate your custom multi-page widget, you must reimplement all the functions of <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a>:</p>
<pre class="cpp"> <span class="type">void</span> MultiPageWidgetContainerExtension<span class="operator">::</span>addWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget)
 {
     myWidget<span class="operator">-</span><span class="operator">&gt;</span>addPage(widget);
 }

 <span class="type">int</span> MultiPageWidgetContainerExtension<span class="operator">::</span>count() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> myWidget<span class="operator">-</span><span class="operator">&gt;</span>count();
 }

 <span class="type">int</span> MultiPageWidgetContainerExtension<span class="operator">::</span>currentIndex() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> myWidget<span class="operator">-</span><span class="operator">&gt;</span>currentIndex();
 }</pre>
<p>You must reimplement <a href="qdesignercontainerextension.html#addWidget">addWidget()</a> adding a given page to the container, <a href="qdesignercontainerextension.html#count">count()</a> returning the number of pages in the container, and <a href="qdesignercontainerextension.html#currentIndex">currentIndex()</a> returning the index of the currently selected page.</p>
<pre class="cpp"> <span class="type">void</span> MultiPageWidgetContainerExtension<span class="operator">::</span>insertWidget(<span class="type">int</span> index<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget)
 {
     myWidget<span class="operator">-</span><span class="operator">&gt;</span>insertPage(index<span class="operator">,</span> widget);
 }

 <span class="type">void</span> MultiPageWidgetContainerExtension<span class="operator">::</span>remove(<span class="type">int</span> index)
 {
     myWidget<span class="operator">-</span><span class="operator">&gt;</span>removePage(index);
 }

 <span class="type">void</span> MultiPageWidgetContainerExtension<span class="operator">::</span>setCurrentIndex(<span class="type">int</span> index)
 {
     myWidget<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(index);
 }

 <span class="type"><a href="qwidget.html">QWidget</a></span><span class="operator">*</span> MultiPageWidgetContainerExtension<span class="operator">::</span>widget(<span class="type">int</span> index) <span class="keyword">const</span>
 {
     <span class="keyword">return</span> myWidget<span class="operator">-</span><span class="operator">&gt;</span>widget(index);
 }</pre>
<p>You must reimplement <a href="qdesignercontainerextension.html#insertWidget">insertWidget()</a> adding a given page to the container at a given index, <a href="qdesignercontainerextension.html#remove">remove()</a> deleting the page at a given index, <a href="qdesignercontainerextension.html#setCurrentIndex">setCurrentIndex()</a> setting the index of the currently selected page, and finally <a href="qdesignercontainerextension.html#widget">widget()</a> returning the page at a given index.</p>
<a name="multipagewidget-class-definition"></a>
<h2>MultiPageWidget Class Definition</h2>
<p>The MultiPageWidget class is a custom container widget that lets the user manipulate and populate its pages, and navigate among these using a combobox.</p>
<pre class="cpp"> <span class="keyword">class</span> MultiPageWidget : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span>
 {
     Q_OBJECT
     Q_PROPERTY(<span class="type">int</span> currentIndex READ currentIndex WRITE setCurrentIndex)
     Q_PROPERTY(<span class="type"><a href="qstring.html">QString</a></span> pageTitle READ pageTitle WRITE setPageTitle STORED <span class="keyword">false</span>)

 <span class="keyword">public</span>:
     MultiPageWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>);

     <span class="type"><a href="qsize.html">QSize</a></span> sizeHint() <span class="keyword">const</span>;

     <span class="type">int</span> count() <span class="keyword">const</span>;
     <span class="type">int</span> currentIndex() <span class="keyword">const</span>;
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget(<span class="type">int</span> index);
     <span class="type"><a href="qstring.html">QString</a></span> pageTitle() <span class="keyword">const</span>;

 <span class="keyword">public</span> <span class="keyword">slots</span>:
     <span class="type">void</span> addPage(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>page);
     <span class="type">void</span> insertPage(<span class="type">int</span> index<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>page);
     <span class="type">void</span> removePage(<span class="type">int</span> index);
     <span class="type">void</span> setPageTitle(<span class="type"><a href="qstring.html">QString</a></span> <span class="keyword">const</span> <span class="operator">&amp;</span>newTitle);
     <span class="type">void</span> setCurrentIndex(<span class="type">int</span> index);

 <span class="keyword">signals</span>:
     <span class="type">void</span> currentIndexChanged(<span class="type">int</span> index);
     <span class="type">void</span> pageTitleChanged(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>title);

 <span class="keyword">private</span>:
     <span class="type"><a href="qstackedwidget.html">QStackedWidget</a></span> <span class="operator">*</span>stackWidget;
     <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>comboBox;
     <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>layout;
 };</pre>
<p>The main detail to observe is that your custom multi-page widget must implement functionality corresponding to the <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a>'s member functions since the <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a> class only is intended to provide Qt Designer access to your custom multi-page widget's functionality.</p>
<p>In addition, we declare the <tt>currentIndex</tt> and <tt>pageTitle</tt> properties, and their associated set and get functions. By declaring these attributes as properties, we allow <i>Qt Designer</i> to manage them in the same way it manages the properties the MultiPageWidget widget inherits from <a href="qwidget.html">QWidget</a> and <a href="qobject.html">QObject</a>, for example featuring the property editor.</p>
<p>Note the <tt>STORED</tt> attribute in the declaration of the <tt>pageTitle</tt> property: The <tt>STORED</tt> attribute indicates persistence, i.e&#x2e; it declares whether the property's value must be remembered when storing an object's state. As mentioned above, we have chosen to store the page title using the <a href="qwidget.html#windowTitle-prop">QWidget::windowTitle</a> property to be able to give each page their own title. For that reason the <tt>pageTitle</tt> property is a &quot;fake&quot; property, provided for editing purposes, and doesn't need to be stored.</p>
<p>We must also implement and emit the currentIndexChanged() and pageTitleChanged() signals to ensure that <i>Qt Designer</i>'s property editor is updated whenever the user views another page or changes one of the page titles.</p>
<p>See the MultiPageWidget class <a href="designer-containerextension-multipagewidget-cpp.html">implementation</a> for more details.</p>
</div>
<!-- @@@designer/containerextension -->
      </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>