Qt switch button in Slicer

Hi all,

I am thinking about using the qt switch button in Slicer as shown here Switch QML Type | Qt Quick Controls 5.15.8. However, I could not find it in Slicer. Does Slicer incorporate the qt switch button function as python script?

Thank you!

I’ve often thought we should be able to use Qt Quick in Slicer but it was never obvious how to do it. If someone has time to explore this it could be fun to try but for now I’d suggest using a QCheckBox instead.

Thank you for letting me know! I was thinking about using the switch button to toggle displaying some results. I’ll use QRadioButton or QCheckbox instead.

I think it looks more modern and clear in places where you need to toggle visibility of something (see below). Of course checkbox or radio buttons can do the job, but I think it Switch is far more intuitive then explaining what that checkbox does in a tool tip.

image

^In your case @muratmaga it would seem like some re-wording could be done where it would be:

"Show Mean point label: [ ] "

The checkbox shouldn’t require any additional tooltip. Should be intuitive that a checked field here would show the mean point label and an unchecked field would mean that it is not showing.

Just a suggestion considering the Switch object is not available to use.

We used to have checkboxes in there, with a label that read toggle mean shape visibility followed by a checkbox. Surprisingly it wasn’t clear to the people. I think the checkboxes and stuff are going out of favor in UI design.

That’s why we now have button, which unfortunately don’t work really well in dark mode due to low contrast, when it is in pressed down state. Having sliding on/off switches would have been nice.

With Qt stylesheets, you can replace the rendered checkbox with an arbitrary image to create the switch look and feel

To do this:

  • Add the images to your module as resources
  • Create a stylesheet (.qss) for the checkbox design and add as a resource
  • Add checkbox.setStylesheet({the contents of the qss file})
    • You can also just embed the qss as a string in the .py file instead of using a separate .qss
  • Example
3 Likes

Yeah the term “Toggle” implies a switch type. Which is why my terminology of “Show” may be the better term for now.

1 Like

This looks great. Thank you!

Hi,

I wanted to ask did you encounter a segmentation fault when using any stylesheet applied (even through SlicerSandbox) and you go to the Transform module and then switch to some other module?

I already asked this question but got no feedback. Currently I’m unable to test it on Windows (slow PC and internet connection).