# When I add ui , cxx, h to my module, how can add source file?

**URL:** https://discourse.slicer.org/t/when-i-add-ui-cxx-h-to-my-module-how-can-add-source-file/20660
**Category:** Development
**Tags:** extensions
**Created:** [November 17, 2021, 1:45pm UTC](https://discourse.slicer.org/t/when-i-add-ui-cxx-h-to-my-module-how-can-add-source-file/20660 "2021-11-17T13:45:05Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kookoo9999](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kookoo9999/32/12394_2.png) [@kookoo9999](https://discourse.slicer.org/u/kookoo9999)
#### Post date: [November 17, 2021, 1:45pm UTC](https://discourse.slicer.org/t/when-i-add-ui-cxx-h-to-my-module-how-can-add-source-file/20660/1 "2021-11-17T13:45:05Z")

</div>

Hello all.  
Is there a way to add these(.ui , .cxx , .h ) at once? Do you usually add .cxx and .h after adding ui by one click or easily way??

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/a/1a4fd15641bdf3d79cb19d169801aa0ce6699078.png)  
and I don’t know the roles of a and the rest of the project.(mymodule, mymoduleWidget ,Logic, LogicPython, etc…).  
For example I can add resouce and its class( test.cpp & test.h) easy in MFC . I know way like this.  
Or do I need to edit it and build it through CMAKE? I wonder if there is such a tutorial.

I tried the above-mentioned method, but I am not sure how to deal with the functions of ui that I randomly added in the module project.

Thanks for reading this.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [November 17, 2021, 6:15pm UTC](https://discourse.slicer.org/t/when-i-add-ui-cxx-h-to-my-module-how-can-add-source-file/20660/2 "2021-11-17T18:15:56Z")

</div>

> [@kookoo9999](#):
>
> For example I can add resouce and its class( test.cpp & test.h) easy in MFC . I know way like this.  
> Or do I need to edit it and build it through CMAKE? I wonder if there is such a tutorial.

Maybe QtDesigner or QtCreator has wizards for creating ui/cxx/h/\_p.h skeletons that is similar to Visual Studio’s MFC class wizards. These can be indeed useful for the first few classes when you create a new application from scratch. If you already have an application, then you would lose a lot of time making general-purpose skeletons created by the Wizard conform to your application’s conventions. Instead it is much faster and simpler to find another class in the application that is very similar to what you need and copy and rename it and adapt it to your needs.

> [@kookoo9999](#):
>
> Or do I need to edit it and build it through CMAKE? I wonder if there is such a tutorial.

You follow generic Qt application development process using CMake and Visual Studio. There is nothing specific to Slicer. All these tools are use by many people, so probably you can find tutorials out there, but you can also just learn by reading the code.

In the end, you will just copy files (.cxx, .h, .ui, …), rename them and rename the class contained in them, and add the new files to the CMakeLists.txt file.

---

<div class="post-metadata">

### Author: ![kookoo9999](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kookoo9999/32/12394_2.png) [@kookoo9999](https://discourse.slicer.org/u/kookoo9999)
#### Post date: [November 18, 2021, 1:01am UTC](https://discourse.slicer.org/t/when-i-add-ui-cxx-h-to-my-module-how-can-add-source-file/20660/3 "2021-11-18T01:01:42Z")

</div>

Thanks for your kindness @lassoan🙂 . I’ve been learning a lot from your kind explanation for a few days.  
One difficult part is the difference and function between mymodule.ui and mymodulewidget.ui. And if I look at the script module, I understand what logic does within python, but where should I define the function according to the event for the button or other tool in c++?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [November 18, 2021, 2:26pm UTC](https://discourse.slicer.org/t/when-i-add-ui-cxx-h-to-my-module-how-can-add-source-file/20660/4 "2021-11-18T14:26:01Z")

</div>

Usually a module has a widget that appears on the left panel. It is always built using a .ui file.

Many modules offer reusable widgets that other modules can use. If such a widget is composed of many other widgets then it is often built using a .ui file, too.

---

<div class="post-metadata">

### Author: ![nnzzll](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nnzzll/32/16350_2.png) [@nnzzll](https://discourse.slicer.org/u/nnzzll)
#### Post date: [August 30, 2022, 11:31am UTC](https://discourse.slicer.org/t/when-i-add-ui-cxx-h-to-my-module-how-can-add-source-file/20660/5 "2022-08-30T11:31:58Z")

</div>

I’d like to customize the extension using totally new ui designed by myself. However, as you said, the extension widget is inserted to the module panel widget. How to setup the widget ui in the main window?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [August 30, 2022, 8:11pm UTC](https://discourse.slicer.org/t/when-i-add-ui-cxx-h-to-my-module-how-can-add-source-file/20660/6 "2022-08-30T20:11:45Z")

</div>

You can hide all built-in Slicer GUI components that you don’t want your users to see (using [set…visible() functions in slicer.util](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#module-slicer.util) package, for example `slicer.util.setMenuBarsVisible(False)`), then add any widgets, docking windows, etc. anywhere you want using Qt. If you have any specific questions then let us know.

---

<div class="post-metadata">

### Author: ![nnzzll](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nnzzll/32/16350_2.png) [@nnzzll](https://discourse.slicer.org/u/nnzzll)
#### Post date: [August 31, 2022, 3:51am UTC](https://discourse.slicer.org/t/when-i-add-ui-cxx-h-to-my-module-how-can-add-source-file/20660/7 "2022-08-31T03:51:11Z")

</div>

Thanks for the reply and I do have a question.  
setVisible() function works in python interactor, however , I’m working on a loadable extension. I called the setVisible() method of the module panel widget in the `enter()` method and it doesn’t work.  
Here is my code:

```auto
void qSlicerVelaTraumaModuleWidget::enter()
{
  Q_D(qSlicerVelaTraumaModuleWidget);
  this->Superclass::enter();
  auto app = qSlicerApplication::application();
  auto modulePanel = app->mainWindow()->findChildren<QDockWidget*>();
  qDebug() << modulePanel.count();
  for(int i=0;i<modulePanel.count();i++)
  {
    qDebug() << modulePanel.at(i);
    modulePanel.at(i)->setVisible(false);
  }
}

```

The `qDebug() << modulePanel.at(i);` line do return the right `QDockWidget` but the `setVisible(false)` call doesn’t work at all.
