Difference between revisions of "Documentation/4.0/Developers/Tutorials/QtDesigner"

From Slicer Wiki
Jump to: navigation, search
m (Move from Slicer3 to Slicer4)
(Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=2887)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Slicer4:QtPort|QtSlicer]]/[[Slicer4:QtPort/Tutorials|Tutorials]]←
+
<noinclude>{{documentation/versioncheck}}</noinclude>
 +
Back to [[Documentation/{{documentation/version}}/Developers|Developers Information]]&larr;
 +
 
 
=Using custom widgets in Qt Designer=
 
=Using custom widgets in Qt Designer=
 
==Straight to the point==
 
==Straight to the point==
 
*Windows
 
*Windows
**Compile Slicer in Release mode
+
**Compile Slicer in Release mode OR build Qt in Debug
**Double clic on <i>Designer-Release.py</i> located in <i>Slicer3-build</i>
+
*All
*Others
 
 
<pre>
 
<pre>
 
cd Slicer-build;
 
cd Slicer-build;
Slicer4 --launch designer
+
./Slicer --designer
 
</pre>
 
</pre>
  
 
==Qt Designer requirements==
 
==Qt Designer requirements==
In order to have the CTK and MRML widgets in Qt Designer, Qt Designer offers 2 options. The first (not detailed here) is to copy (or symlink) the CTK and MRML plugin libraries into <i>%QT_DIR%/plugins/designer</i>, the second is to set the environment variable <code>QT_PLUGIN_PATH</code> to the directory <i>Slicer3-build/bin</i> containing the subdirectory <i>designer</i> with the plugin libraries.<br>
+
In order to have the CTK and MRML widgets in Qt Designer, Qt Designer offers 2 options:
 +
*the first (not detailed here) is to copy (or symlink) the CTK and MRML plugin libraries into <i>%QT_DIR%/plugins/designer</i>,
 +
*the second is to set the environment variable <code>QT_PLUGIN_PATH</code> to the directory <i>Slicer-build/bin</i> containing the subdirectory <i>designer</i> with the plugin libraries.<br>
 
'''Note:''' Qt requires that the directory containing the designer plugins is named "designer".<br>
 
'''Note:''' Qt requires that the directory containing the designer plugins is named "designer".<br>
Moreover, Qt Designer can only load plugins that have been compiled in the same build mode than Qt Designer. For example, if Qt is built in Debug mode, the plugins must also be built in Debug mode to be loaded by Qt Designer.<br>
+
=== Windows notes ===
'''Note:''' If Qt is configured to build in both debug and release modes, Qt Designer is built in release mode only. If that case, it is necessary to ensure that plugins are also built in release mode.  
+
On Windows, Qt Designer can only load plugins that have been compiled in the same build mode than Qt Designer. For example, if Qt is built in Debug mode, the plugins must also be built in Debug mode to be loaded by Qt Designer.<br>
 +
If Qt is configured to build in both debug and release modes, Qt Designer is built in release mode only. If that case, it is necessary to ensure that plugins are also built in release mode. Otherwise, you can open the solution file for Qt, and recompile Designer in debug mode.
  
 
==Running Qt Designer with the correct environment variables==
 
==Running Qt Designer with the correct environment variables==
*Compile Slicer in the same build mode than Qt. If Qt is in Debug mode, compile Slicer in Debug mode, if it's in Release or Debug&Release mode, compile Slicer in Release mode.
+
*On Windows, compile Slicer in the same build mode than Qt. If Qt is in Debug mode, compile Slicer in Debug mode, if it's in Release or Debug&Release mode, compile Slicer in Release mode.
 
*run Qt Designer via Slicer launcher located in <i>Slicer-build</i>.
 
*run Qt Designer via Slicer launcher located in <i>Slicer-build</i>.
<pre>
+
{| style="border: 1px solid darkgray;"
cd Slicer-build;
+
!align=left style="border-bottom: 1px solid grey;"|Mac Os X
Slicer4 --designer
+
!align=left style="border-bottom: 1px solid grey;"|Linux
</pre>
+
!align=left style="border-bottom: 1px solid grey;"|Windows
'''Note:''' For MS Visual Studio users, there is a <i>Designer</i> python script for each build mode. Execute the script according to the build mode.
+
|-
'''Note:''' <i>Designer.py</i> can take a <i>.ui</i> file as an argument, it will load it into Qt designer.
+
|colspan="2"|
 +
$ cd Slicer-build
 +
$ ./Slicer --designer
 +
|
 +
> cd Slicer-build
 +
> .\Slicer.exe --designer
 +
|}
 
{|
 
{|
 
|[[Image:Screenshot-Qt Designer.png|thumb|300px|Qt Desginer loaded with CTKWidgets and qMRMLWidgets]]
 
|[[Image:Screenshot-Qt Designer.png|thumb|300px|Qt Desginer loaded with CTKWidgets and qMRMLWidgets]]
 +
|}
 +
 +
==Build Slicer==
 +
* Once you are satisfied with UI, save the file, quit Designer and build Slicer to take the changes into account.
 +
{| style="border: 1px solid darkgray;"
 +
!align=left style="border-bottom: 1px solid grey;"|Mac Os X
 +
!align=left style="border-bottom: 1px solid grey;"|Linux
 +
!align=left style="border-bottom: 1px solid grey;"|Windows
 +
|-
 +
|colspan="2"|<pre>$ make -j4</pre>
 +
| Open the inner solution file ''...Slicer-Superbuild\Slicer-build\Slicer.sln'' and build the solution (F7) or build project <code>qSlicerMY_MODULE_NAMEModuleWidgets</code>
 +
|}
 +
It generates a ''ui_qSlicerMY_MODULE_NAMEModule.h'' file in ''...Slicer-Superbuild/Slicer-buildModules/Loadable/MY_MODULE_NAME/''.
 +
 +
That file is used by ''...Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAMEModuleWidget.cxx''.
 +
 +
Note: The <code>objectName</code>s of each widget in the UI correspond (see the Property editor) to the variable names in C++. From your code, you can access the widgets by their objectName.
 +
* And launch Slicer to see the result
 +
{| style="border: 1px solid darkgray;"
 +
!align=left style="border-bottom: 1px solid grey;"|Mac Os X
 +
!align=left style="border-bottom: 1px solid grey;"|Linux
 +
!align=left style="border-bottom: 1px solid grey;"|Windows
 +
|-
 +
|colspan="2"|<pre>$ ./Slicer</pre>
 +
| <pre>> .\Slicer.exe</pre>
 
|}
 
|}

Latest revision as of 07:29, 14 June 2013

Home < Documentation < 4.0 < Developers < Tutorials < QtDesigner


For the latest Slicer documentation, visit the read-the-docs.


Back to Developers Information

Using custom widgets in Qt Designer

Straight to the point

  • Windows
    • Compile Slicer in Release mode OR build Qt in Debug
  • All
cd Slicer-build;
./Slicer --designer

Qt Designer requirements

In order to have the CTK and MRML widgets in Qt Designer, Qt Designer offers 2 options:

  • the first (not detailed here) is to copy (or symlink) the CTK and MRML plugin libraries into %QT_DIR%/plugins/designer,
  • the second is to set the environment variable QT_PLUGIN_PATH to the directory Slicer-build/bin containing the subdirectory designer with the plugin libraries.

Note: Qt requires that the directory containing the designer plugins is named "designer".

Windows notes

On Windows, Qt Designer can only load plugins that have been compiled in the same build mode than Qt Designer. For example, if Qt is built in Debug mode, the plugins must also be built in Debug mode to be loaded by Qt Designer.
If Qt is configured to build in both debug and release modes, Qt Designer is built in release mode only. If that case, it is necessary to ensure that plugins are also built in release mode. Otherwise, you can open the solution file for Qt, and recompile Designer in debug mode.

Running Qt Designer with the correct environment variables

  • On Windows, compile Slicer in the same build mode than Qt. If Qt is in Debug mode, compile Slicer in Debug mode, if it's in Release or Debug&Release mode, compile Slicer in Release mode.
  • run Qt Designer via Slicer launcher located in Slicer-build.
Mac Os X Linux Windows
$ cd Slicer-build
$ ./Slicer --designer
> cd Slicer-build
> .\Slicer.exe --designer
Qt Desginer loaded with CTKWidgets and qMRMLWidgets

Build Slicer

  • Once you are satisfied with UI, save the file, quit Designer and build Slicer to take the changes into account.
Mac Os X Linux Windows
$ make -j4
Open the inner solution file ...Slicer-Superbuild\Slicer-build\Slicer.sln and build the solution (F7) or build project qSlicerMY_MODULE_NAMEModuleWidgets

It generates a ui_qSlicerMY_MODULE_NAMEModule.h file in ...Slicer-Superbuild/Slicer-buildModules/Loadable/MY_MODULE_NAME/.

That file is used by ...Slicer4/Modules/Loadable/MY_MODULE_NAME/qSlicerMY_MODULE_NAMEModuleWidget.cxx.

Note: The objectNames of each widget in the UI correspond (see the Property editor) to the variable names in C++. From your code, you can access the widgets by their objectName.

  • And launch Slicer to see the result
Mac Os X Linux Windows
$ ./Slicer
> .\Slicer.exe