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

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??

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.

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.

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.

Thanks for your kindness @lassoan :slight_smile: . 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++?

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.

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?

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 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.

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:

void qSlicerVelaTraumaModuleWidget::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);

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