Setting window icon for floating module widget?

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

You might try setting the parent to None like this:

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.

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.

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.

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.

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):

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!

2 Likes