# About the right click on mainwindow’s toolbar

**URL:** <https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027>\
**Category:** Support\
**Tags:** python\
**Created:** [January 10, 2025, 1:07pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027 "2025-01-10T13:07:44Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nih4t](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nih4t/32/78310_2.png) [@nih4t](https://discourse.slicer.org/u/nih4t)\
**Post date:** [January 10, 2025, 1:07pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/1 "2025-01-10T13:07:44Z")

</div>

Hi, how can I edit here?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/b/db60a79c484d2ee12b3e09d88e92fb72d53a14c9.png)

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [January 10, 2025, 2:50pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/2 "2025-01-10T14:50:35Z")

</div>

Can you be more specific please? What do you want to edit?

---

<div class="post-metadata">

**Author:** ![nih4t](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nih4t/32/78310_2.png) [@nih4t](https://discourse.slicer.org/u/nih4t)\
**Post date:** [January 10, 2025, 2:53pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/3 "2025-01-10T14:53:55Z")

</div>

I’m using SlicerCAT right now and I would like to modify the default checked options in this dropdown menu. Can you guide me on how to configure which items are selected by default when the application starts.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [January 10, 2025, 3:28pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/4 "2025-01-10T15:28:14Z")

</div>

You can do this for example:  
`slicer.util.mainWindow().findChildren('qMRMLCaptureToolBar')[0].visible = False`

But there may be a better way to customize this.

---

<div class="post-metadata">

**Author:** ![nih4t](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nih4t/32/78310_2.png) [@nih4t](https://discourse.slicer.org/u/nih4t)\
**Post date:** [January 10, 2025, 4:04pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/5 "2025-01-10T16:04:23Z")

</div>

The code  
`slicer.util.mainWindow().findChildren('qMRMLCaptureToolBar')[0].visible = False`  
works fine in 3D Slicer to hide the Capture/Restore Toolbar. However, in SlicerCAT, the setting doesn’t persist after restarting the application, and the toolbar reverts to its default visibility.

Do you know what the equivalent name is for the “Favorite Modules” in the code? For example, `qMRMLCaptureToolBar` is used for the Capture/Restore toolbar—what would it be for the Favorite Modules?

---

<div class="post-metadata">

**Author:** ![Esteban\_Barreiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/esteban_barreiro/32/5430_2.png) [@Esteban\_Barreiro](https://discourse.slicer.org/u/Esteban_Barreiro)\
**Post date:** [January 11, 2025, 1:51pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/6 "2025-01-11T13:51:44Z")

</div>

Did you try drag and drop the module you want to the favorites tab in user preferences?

---

<div class="post-metadata">

**Author:** ![nih4t](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nih4t/32/78310_2.png) [@nih4t](https://discourse.slicer.org/u/nih4t)\
**Post date:** [January 11, 2025, 2:11pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/7 "2025-01-11T14:11:31Z")

</div>

I know how to add modules to Favorite Modules, so that’s not my question. I’m currently using SlicerCAT, and in SlicerCAT, the “Favorite Modules” section is not checked by default. I want to change this behavior. I have a few ideas to try, but I’m struggling to find the exact name used in the code to represent this section.

For instance, in the code, they used the name “qMRMLCaptureToolBar” to control the “Capture/Restore” functionality. Similarly, I’m looking for the name they used to represent the “Favorite Modules” section shown in the image below. Could anyone point me in the right direction?

 ![IMG_9856](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/b/bb5daebb6b7ac32c75a5147c9fa7933f27ac323e.jpeg)

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 11, 2025, 5:53pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/8 "2025-01-11T17:53:38Z")

</div>

As you begin your customization journey I would suggest reviewing the following technique:

[https://slicer.readthedocs.io/en/latest/developer\_guide/python\_faq.html#how-to-find-a-python-function-for-any-slicer-features](https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html#how-to-find-a-python-function-for-any-slicer-features)

Which would lead you to do the following search in the Slicer repository:

> **[Build software better, together](https://github.com/search?q=repo%3ASlicer%2FSlicer%20favorite%20modules&type=code)**
>
> GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.

Which contains a result for the object name of the QToolBar for that has the display name of “Favorite Modules”.

---

<div class="post-metadata">

**Author:** ![nih4t](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nih4t/32/78310_2.png) [@nih4t](https://discourse.slicer.org/u/nih4t)\
**Post date:** [January 11, 2025, 6:34pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/9 "2025-01-11T18:34:27Z")

</div>

Hi, thanks for your response. I’ve already added my own modules and buttons to SlicerCAT, but I’m facing an issue. Even though I’ve found the name of the “Favorite Modules” toolbar, my initial solution didn’t work as expected, so I need some help.

Here’s the situation: I’ve successfully added my custom modules and their buttons, and I’ve also included some 3D Slicer modules to the “Favorite Modules” section. However, in SlicerCAT, “Favorite Modules” is invisible by default. I need to right-click and manually enable them. I’d like to change this default behavior so that the modules are visible by default.

Additionally, I want to disable right-click functionality on the main toolbar to prevent users from modifying the module visibility. This would allow me to hide unnecessary modules from the users.

For reference, here is the source code of SlicerCAT:

> **[GitHub - KitwareMedical/SlicerCAT: Example Application for Slicer Customization -...](https://github.com/KitwareMedical/SlicerCAT)**
>
> Example Application for Slicer Customization - Generated from KitwareMedical/SlicerCustomAppTemplate

It seems that the file previously named `Example.py` is now called `Home.py`.

I’ve been struggling to implement these changes. Do you have any suggestions or guidance on how I can achieve this?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 11, 2025, 8:07pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/10 "2025-01-11T20:07:37Z")

</div>

Although you can look at SlicerCAT as an example, it is just a snapshot in time of what [SlicerCustomAppTemplate](https://github.com/KitwareMedical/SlicerCustomAppTemplate) produced over 3 years ago. The Home.py is what SlicerCustomAppTemplate currently creates and has last customization examples.

In the below linked code you can customize which toolbars are set as visible on startup.

> <https://github.com/KitwareMedical/SlicerCustomAppTemplate/blob/5a783789781f3c86615d35c41a9db5ac8ade34b1/%7B%7Bcookiecutter.project_name%7D%7D/Modules/Scripted/Home/Home.py#L96>

> [@nih4t](#):
>
> Additionally, I want to disable right-click functionality on the main toolbar to prevent users from modifying the module visibility.

^Regarding this type of customization it is something I’ve never done before. Editing toolbar visibility through right-click is standard Qt behavior. Since this would be standard Qt type customization not unique to Slicer you may be able to search on various Qt forums about how to accomplish this task.

> [@nih4t](#):
>
> This would allow me to hide unnecessary modules from the users.

If there are modules that you don’t need at all, you can modify your Slicer custom application to not include the modules in the first place rather than worrying about trying to hide them. This can be customized at:

> <https://github.com/KitwareMedical/SlicerCustomAppTemplate/blob/5a783789781f3c86615d35c41a9db5ac8ade34b1/%7B%7Bcookiecutter.project_name%7D%7D/CMakeLists.txt#L121>

---

<div class="post-metadata">

**Author:** ![nih4t](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nih4t/32/78310_2.png) [@nih4t](https://discourse.slicer.org/u/nih4t)\
**Post date:** [January 12, 2025, 1:25pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/11 "2025-01-12T13:25:15Z")

</div>

Thanks for your response. I actually tried this earlier when you shared the object name for “Favorite Modules.” I believe it’s `"ModuleToolBar"`. However, I tried it, and it didn’t work as expected. Here’s the code I used:

```auto
def setSlicerUIVisible(self, visible: bool):
    exemptToolbars = [
        "MainToolBar",
        "ViewToolBar",
        "ModuleToolBar",
        *self.toolbarNames,
    ]

    slicer.util.setDataProbeVisible(visible)
    slicer.util.setMenuBarsVisible(visible, ignore=exemptToolbars)
    slicer.util.setModuleHelpSectionVisible(visible)
    slicer.util.setModulePanelTitleVisible(visible)
    slicer.util.setPythonConsoleVisible(visible)
    slicer.util.setApplicationLogoVisible(visible)
    keepToolbars = [
        slicer.util.findChild(slicer.util.mainWindow(), toolbarName) 
        for toolbarName in exemptToolbars
    ]
    slicer.util.setToolbarsVisible(visible, keepToolbars)

```

For the `CMakeLists.txt`, you can see that almost everything is currently disabled. I always thought that we could manage the modules already listed in this file and toggle them between enabled or disabled. My question is: if I add an object name here, will it automatically disable the corresponding module? If that’s the case, I’ll need to identify the object name for every module I want to manage.

Here’s the current configuration of my `CMakeLists.txt` file:

```auto
# Enable Slicer built-in modules
set(Slicer_CLIMODULES_ENABLED
  ResampleDTIVolume # Needed by ResampleScalarVectorDWIVolume
  ResampleScalarVectorDWIVolume # Depends on DiffusionApplications, needed by CropVolume
)

set(Slicer_QTLOADABLEMODULES_ENABLED
)

set(Slicer_QTSCRIPTEDMODULES_ENABLED
)

# Disable Slicer built-in modules
set(Slicer_CLIMODULES_DISABLED
)

set(Slicer_QTLOADABLEMODULES_DISABLED
  SceneViews
  SlicerWelcome
  ViewControllers
)

set(Slicer_QTSCRIPTEDMODULES_DISABLED
  DataProbe
  DMRIInstall
  Endoscopy
  LabelStatistics
  PerformanceTests
  SampleData
  VectorToScalarVolume
)

```

I’ll include two images below to show you the current version of my configuration and the target version I aim to achieve.

The version that I have right now looks like this. You can riğht click and enable what you want.

 ![Ekran görüntüsü 2025-01-12 132405](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/c/5c7b88f6e5596ffadbc14ca8797e25192d4218ee.png)

And this is the version that I want to achive, just these modules enabled (They are currently in Favorite Modules) and I don’t want any other thing. I want to start slicer and see this screen. And I don’t need any other functionality.

 ![Ekran görüntüsü 2025-01-12 132449](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/8/f837379d5fe2a89bbbefd2b8a266be8d6ef87f2f.png)

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 12, 2025, 2:02pm UTC](https://discourse.slicer.org/t/about-the-right-click-on-mainwindow-s-toolbar/41027/12 "2025-01-12T14:02:28Z")

</div>

> [@nih4t](#):
>
> However, I tried it, and it didn’t work as expected. Here’s the code I used:

Have you confirmed that any edits to the Home.py are working? Have you tried a print statement of some sort to see if it gets executed. There may be a Home.pyc file which I believe you will need to delete first as that is the compiled version that is ultimately run. If no pyc version is present it goes back to using the py version of the file.

> [@nih4t](#):
>
> My question is: if I add an object name here, will it automatically disable the corresponding module?

If you add a module to the disabled list I would expect that you would first new to delete the module contents that were copied into the Slicer build tree and then run the incremental build of Slicer again. I don’t believe the build process will remove module files already copied into the Slicer-build area. For sure if you run a completely new build of the application would it respect the updated module disabled list. Modifying the CMakeLists.txt and running the application without re-running the build won’t do anything.
