<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QDesignerTaskMenuExtension Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" 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="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QDesignerTaskMenuExtension Class Reference<br /><sup><sup>[<a href="qtdesigner.html">QtDesigner</a> module]</sup></sup></h1><p>The QDesignerTaskMenuExtension class allows you to add custom menu entries to Qt Designer's task menu. <a href="#details">More...</a></p> <p>Inherited by <a href="qpydesignertaskmenuextension.html">QPyDesignerTaskMenuExtension</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qdesignertaskmenuextension.html#QDesignerTaskMenuExtension">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qdesignertaskmenuextension.html#QDesignerTaskMenuExtension-2">__init__</a></b> (<i>self</i>, QDesignerTaskMenuExtension)</li><li><div class="fn" />QAction <b><a href="qdesignertaskmenuextension.html#preferredEditAction">preferredEditAction</a></b> (<i>self</i>)</li><li><div class="fn" />list-of-QAction <b><a href="qdesignertaskmenuextension.html#taskActions">taskActions</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QDesignerTaskMenuExtension class allows you to add custom menu entries to Qt Designer's task menu.</p> <p>QDesignerTaskMenuExtension provides an interface for creating custom task menu extensions. It is typically used to create task menu entries that are specific to a plugin in <i>Qt Designer</i>.</p> <p><i>Qt Designer</i> uses the QDesignerTaskMenuExtension to feed its task menu. Whenever a task menu is requested, <i>Qt Designer</i> will query for the selected widget's task menu extension.</p> <p class="centerAlign"><img alt="" src="images/taskmenuextension-example-faded.png" /></p> <p>A task menu extension is a collection of QActions. The actions appear as entries in the task menu when the plugin with the specified extension is selected. The image above shows the custom <b>Edit State...</b> action which appears in addition to <i>Qt Designer</i>'s default task menu entries: <b>Cut</b>, <b>Copy</b>, <b>Paste</b> etc.</p> <p>To create a custom task menu extension, your extension class must inherit from both <a href="qobject.html">QObject</a> and QDesignerTaskMenuExtension. For example:</p> <pre class="cpp"> <span class="keyword">class</span> MyTaskMenuExtension : <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">QDesignerTaskMenuExtension</span> { Q_OBJECT Q_INTERFACES(<span class="type">QDesignerTaskMenuExtension</span>) <span class="keyword">public</span>: MyTaskMenuExtension(MyCustomWidget <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="qaction.html">QAction</a></span> <span class="operator">*</span>preferredEditAction() <span class="keyword">const</span>; <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span><span class="operator">></span> taskActions() <span class="keyword">const</span>; <span class="keyword">private</span> <span class="keyword">slots</span>: <span class="type">void</span> mySlot(); <span class="keyword">private</span>: MyCustomWidget <span class="operator">*</span>widget; <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>myAction; }; </pre> <p>Since we are implementing an interface, we must ensure that it is 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 the <a href="qobject.html#qobject_cast">qobject_cast</a>() function to query for supported interfaces using nothing but a <a href="qobject.html">QObject</a> pointer.</p> <p>You must reimplement the <a href="qdesignertaskmenuextension.html#taskActions">taskActions</a>() function to return a list of actions that will be included in <i>Qt Designer</i> task menu. Optionally, you can reimplement the <a href="qdesignertaskmenuextension.html#preferredEditAction">preferredEditAction</a>() function to set the action that is invoked when selecting your plugin and pressing <b>F2</b>. The preferred edit action must be one of the actions returned by <a href="qdesignertaskmenuextension.html#taskActions">taskActions</a>() and, if it's not defined, pressing the <b>F2</b> key will simply be ignored.</p> <p>In <i>Qt Designer</i>, extensions are not created until they are required. A task menu extension, for example, is created when you click the right mouse button over a widget in <i>Qt Designer</i>'s workspace. For that reason you must also construct an extension factory, using either <a href="qextensionfactory.html">QExtensionFactory</a> or a subclass, and register it using <i>Qt Designer</i>'s <a href="qextensionmanager.html">extension manager</a>.</p> <p>When a task menu extension is required, <i>Qt Designer</i>'s <a href="qextensionmanager.html">extension manager</a> will run through all its registered factories calling <a href="qextensionfactory.html#createExtension">QExtensionFactory.createExtension</a>() for each until it finds one that is able to create a task menu extension for the selected widget. This factory will then make an instance of the extension.</p> <p>There are four available types of extensions in <i>Qt Designer</i>: <a href="qdesignercontainerextension.html">QDesignerContainerExtension</a>, <a href="qdesignermembersheetextension.html">QDesignerMemberSheetExtension</a>, <a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a>, and QDesignerTaskMenuExtension. <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.</p> <p>The <a href="qextensionfactory.html">QExtensionFactory</a> class provides a standard extension factory, and can also be used as an interface for custom extension factories. You can either create a new <a href="qextensionfactory.html">QExtensionFactory</a> and reimplement the <a href="qextensionfactory.html#createExtension">QExtensionFactory.createExtension</a>() function. For example:</p> <pre class="cpp"> <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>ANewExtensionFactory<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">&</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> { <span class="keyword">if</span> (iid <span class="operator">!</span><span class="operator">=</span> Q_TYPEID(<span class="type">QDesignerTaskMenuExtension</span>)) <span class="keyword">return</span> <span class="number">0</span>; <span class="keyword">if</span> (MyCustomWidget <span class="operator">*</span>widget <span class="operator">=</span> qobject_cast<span class="operator"><</span>MyCustomWidget<span class="operator">*</span><span class="operator">></span>(object)) <span class="keyword">return</span> <span class="keyword">new</span> MyTaskMenuExtension(widget<span class="operator">,</span> parent); <span class="keyword">return</span> <span class="number">0</span>; } </pre> <p>Or you can use an existing factory, expanding the <a href="qextensionfactory.html#createExtension">QExtensionFactory.createExtension</a>() function to make the factory able to create a task menu extension as well. For example:</p> <pre class="cpp"> <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>AGeneralExtensionFactory<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">&</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> { MyCustomWidget <span class="operator">*</span>widget <span class="operator">=</span> qobject_cast<span class="operator"><</span>MyCustomWidget<span class="operator">*</span><span class="operator">></span>(object); <span class="keyword">if</span> (widget <span class="operator">&</span><span class="operator">&</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> MyContainerExtension(widget<span class="operator">,</span> parent); } <span class="keyword">else</span> <span class="keyword">if</span> (widget <span class="operator">&</span><span class="operator">&</span> (iid <span class="operator">=</span><span class="operator">=</span> Q_TYPEID(<span class="type">QDesignerTaskMenuExtension</span>))) { <span class="keyword">return</span> <span class="keyword">new</span> MyTaskMenuExtension(widget<span class="operator">,</span> parent); } <span class="keyword">else</span> { <span class="keyword">return</span> <span class="number">0</span>; } } </pre> <p>For a complete example using the QDesignerTaskMenuExtension class, see the <a href="designer-taskmenuextension.html">Task Menu Extension example</a>. The example shows how to create a custom widget plugin for <i>Qt Designer</i>, and how to to use the QDesignerTaskMenuExtension class to add custom items to <i>Qt Designer</i>'s task menu.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QDesignerTaskMenuExtension" />QDesignerTaskMenuExtension.__init__ (<i>self</i>)</h3><h3 class="fn"><a name="QDesignerTaskMenuExtension-2" />QDesignerTaskMenuExtension.__init__ (<i>self</i>, <a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a>)</h3><h3 class="fn"><a name="preferredEditAction" /><a href="qaction.html">QAction</a> QDesignerTaskMenuExtension.preferredEditAction (<i>self</i>)</h3><p>Returns the action that is invoked when selecting a plugin with the specified extension and pressing <b>F2</b>.</p> <p>The action must be one of the actions returned by <a href="qdesignertaskmenuextension.html#taskActions">taskActions</a>().</p> <h3 class="fn"><a name="taskActions" />list-of-QAction QDesignerTaskMenuExtension.taskActions (<i>self</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Returns the task menu extension as a list of actions which will be included in <i>Qt Designer</i>'s task menu when a plugin with the specified extension is selected.</p> <p>The function must be reimplemented to add actions to the list.</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>