commontk / CTK

A set of common support code for medical imaging, surgical navigation, and related purposes.
https://commontk.org
Apache License 2.0
827 stars 480 forks source link

ENH: Example how to use dynamic properties and stylesheets #1202

Open Punzo opened 2 months ago

Punzo commented 2 months ago

Bare bones example how to use dynamic properties and stylesheets in CTK to replace dynamic QPalette hard coded colors (colors associated to widget states: normal, warning, disabled, etc.). This would allow slicer customizations to replace the dynamic widgets state colors by simply defining them in the styleSheet.

hey @sjh26, @lassoan @jcfr @pieper @cpinter I would appreciate a lot if you can provide feedback. Then if you agree on a solution, I can apply the solution to all the CTK classes that uses the QPalette.

jcfr commented 2 months ago

I suggest to review what we documented here: https://github.com/KitwareMedical/SlicerCustomAppUtilities#styling

Punzo commented 2 months ago

I suggest to review what we documented here: https://github.com/KitwareMedical/SlicerCustomAppUtilities#styling

hei Jc, thanks for sharing the link. I read the repo documentation, but for me it is not clear how it can solve my specific issue. My use case is: 1) I do a query in the visual dicom browser and if no results are found, a yellow background is currently applied to the filters lineEdit widgets by modifying the QPalette (e.g. https://github.com/commontk/CTK/pull/1202/files#diff-db5337d6b1bcecfa29648a6ea7aebd0d7561a07032e6f56af1031e34c1ba4e16R893-R903) 2) If I apply a simple static stylesheet to my customSlicer, the linked QPalette code does not work anymore (the stylesheet overwrites everything). 3) I see that in https://github.com/KitwareMedical/SlicerCustomAppUtilities you are using dynamic properties, but to me it is still not clear how to update the status of the widget in my use case: a) in this draft PR for example I set the property here: https://github.com/commontk/CTK/pull/1202/files#diff-db5337d6b1bcecfa29648a6ea7aebd0d7561a07032e6f56af1031e34c1ba4e16R906-R915 b) in your repo I see these methods to achive that https://github.com/KitwareMedical/SlicerCustomAppUtilities/blob/main/Modules/Scripted/SlicerCustomAppUtilities/SlicerCustomAppUtilities/__init__.py#L16-L42, but you would still need to observe the visual dicom browser widget, something like a signal. e.g., query failed -> signal -> slicerCustomization python module observe the signal and set the dynamic property with your methods. But this still means we would need to add many signals to change dynamically all the CTK widgets that changes colors dynamically with a QPalette (there are many).

Am I missing something?

lassoan commented 2 months ago

@jcfr please suggest changes that would make this code meet the guidelines.

It is not clear for me how they alcan be used here, because we need modifier not just based on theme (light or dark) but also state (normal, warning, disabled, etc.).

The syntax of block/elelement/modifier also seems to be ambiguous, as each component can consists of multiple words, so double-dash or double-underscore should be used to separate them (while in your examples the light and dark modifier was just separated from the element by a single dash).

Punzo commented 1 month ago

@jcfr do you think we should discuss this in a videocall? thanks in advance