# Setting window icon for floating module widget?

**URL:** <https://discourse.slicer.org/t/setting-window-icon-for-floating-module-widget/9819>\
**Category:** Support\
**Created:** [January 14, 2020, 11:02pm UTC](https://discourse.slicer.org/t/setting-window-icon-for-floating-module-widget/9819 "2020-01-14T23:02:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brynpitt](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@brynpitt](https://discourse.slicer.org/u/brynpitt)\
**Post date:** [January 14, 2020, 11:02pm UTC](https://discourse.slicer.org/t/setting-window-icon-for-floating-module-widget/9819/1 "2020-01-14T23:02:25Z")

</div>

Operating system: Windows 10  
Slicer version: 4.11

Hi all–

I have created a module (using the ScriptedLoadableModule template), and I am trying to add a button to the widget GUI that sets the window to full screen.

As part of that, I would also like to set the module widget to float and also change the module window icon to a custom icon. I am able to achieve the desired appearance when launching Slicer with a custom launch script using this code:

> slicer.util.mainWindow().showFullScreen  
> slicer.modules.mymodule.widgetRepresentation().show()  
> slicer.modules.mymodule.widgetRepresentation().setWindowIcon(qt.QIcon(customIconFilePath))

However, once I have opened my module in the module panel in Slicer, the above code that works in the launch script doesn’t show my module in a floating window (but the code runs without error). I assume this has something to do with the fact that my module is already open in the model panel. Is there a way to get around this issue? I would really like to be able to achieve the desired appearance by clicking a button in my module’s GUI rather than launching in full screen.

FYI, I tried to achieve the desired appearance by floating the module panel (after my module was already open in the module panel). Here’s an excerpt of the relevant code:

> slicer.util.mainWindow().showFullScreen  
> moduleBrowser = slicer.util.mainWindow().findChild(“QDockWidget”, “PanelDockWidget”)  
> moduleBrowser.setFloating(True)  
> moduleBrowser.setWindowIcon(qt.QIcon(customIconFilePath))

This code runs without error, but I have two issues:

1. The floating module panel includes the Data Probe and a large Slicer logo. (I’d rather not have those things in the window.)

2. The window icon doesn’t actually change. (No window icon appears at all.)

Can anyone tell me how I can achieve my desired appearance when executing code via a button in the module widget GUI? This is a minor issue, but I would still greatly appreciate any help!

Thanks in advance,  
EBP

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 15, 2020, 12:45am UTC](https://discourse.slicer.org/t/setting-window-icon-for-floating-module-widget/9819/2 "2020-01-15T00:45:32Z")

</div>

You might try setting the parent to None like this:

> <https://github.com/pieper/SlicerAnimator/blob/master/Animator/Animator.py#L701-L702>

---

<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:** [January 15, 2020, 1:54am UTC](https://discourse.slicer.org/t/setting-window-icon-for-floating-module-widget/9819/3 "2020-01-15T01:54:44Z")

</div>

> [@brynpitt](#):
>
> slicer.util.mainWindow().showFullScreen

Full-screen applications are rendered completely differently than windowed applications. If you experience any strange rendering then make the application window maximized and hide the frame but not make the application full-screen.

> [@brynpitt](#):
>
> The floating module panel includes the Data Probe and a large Slicer logo. (I’d rather not have those things in the window.)

There are helper functions that you can use to show/hide different components of the application GUI. You have even more control over everything if you implement a [custom application](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Slicelets#Custom_Slicer_application).

> [@brynpitt](#):
>
> The window icon doesn’t actually change. (No window icon appears at all.)

The module panel is a QDockWidget, which does not have a window icon. You can of course always override the paint function and create a custom widget that does paint itself with an icon.

> [@brynpitt](#):
>
> how I can achieve my desired appearance

From a textual description it is hard to catch what is the desired appearance. Posting a few screenshots, showing what you want and what you get would help a lot in understanding it.

---

<div class="post-metadata">

**Author:** ![brynpitt](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@brynpitt](https://discourse.slicer.org/u/brynpitt)\
**Post date:** [January 21, 2020, 3:59pm UTC](https://discourse.slicer.org/t/setting-window-icon-for-floating-module-widget/9819/4 "2020-01-21T15:59:10Z")

</div>

Using setParent(None) fixed my issue!

To help future users who might have a similar issue, here is a screen shot of my desired behavior (using the Data module as an example):

 ![slicer_prnt_scrn](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/5/056a1d6e3adf52afeb73306719787e96d8fb6f78.png)

This issue I was having was that if the target modules (the Data module in the example) was already open in the Module Browser (which is set to be invisible), then

> slicer.modules.data.widgetRepresentation().show()

would not show the Data module as desired. This issue was fixed using @pieper’s suggestion:

> slicer.modules.data.widgetRepresentation().setParent(None)

before showing the module. I could then change the window icon as desired (not shown in the screen shot above).

Thanks for the help!
