Returns the string that contain CSS to set widget background to specified color
(rgb, widget="QWidget", editable=False)
| 367 | |
| 368 | |
| 369 | def get_background_css(rgb, widget="QWidget", editable=False): |
| 370 | """Returns the string that contain CSS to set widget background to specified color""" |
| 371 | |
| 372 | rgb = tuple(rgb) |
| 373 | if len(rgb) != 3: |
| 374 | raise ValueError(r"RGB must be represented by 3 elements: rgb = {rgb}") |
| 375 | if any([(_ > 255) or (_ < 0) for _ in rgb]): |
| 376 | raise ValueError(r"RGB values must be in the range 0..255: rgb={rgb}") |
| 377 | |
| 378 | # Shaded widgets appear brighter, so the brightness needs to be reduced |
| 379 | shaded_widgets = ("QComboBox", "QPushButton") |
| 380 | if widget in shaded_widgets: |
| 381 | rgb = [max(int(255 - (255 - _) * 1.5), 0) for _ in rgb] |
| 382 | |
| 383 | # Increase brightness of editable element |
| 384 | if editable: |
| 385 | rgb = [255 - int((255 - _) * 0.5) for _ in rgb] |
| 386 | |
| 387 | color_css = f"rgb({rgb[0]}, {rgb[1]}, {rgb[2]})" |
| 388 | return f"{widget} {{ background-color: {color_css}; }}" |
| 389 | |
| 390 | |
| 391 | class IntValidatorStrict(QIntValidator): |
no outgoing calls
no test coverage detected