Qt background color inconsistency

I would like to use background-color in a custom smtk view, but the Qt and/or macOS behavior not consistent between light and dark modes. I’ll outline below. If anyone has worked this out, please let me know!

  • I am using Qt stylesheets to set the background color.
  • In light-mode, the stylesheet background color is all good.
  • But in dark-mofr, the background color is inherited by all children widgets. (I can change the background color in dark mode to restore contrast, but the buttons and other widgets still inherit the background color.)
  • I could also reverse engineer css for the buttons and other widgets inside the custom view, but that seems way too fragile.
  • I also tried removing the stylesheet completely and instead set colors in QPalette: On my mac (x86 cpu, macOS Monterey 12.6), setting the view widget’s QPalette colors for Qt::Window, Qt::Background, or Qt::Window has no effect on the display.
  • So my current plan is to give up on background color and go with a heavier, colored border. Hardly the visual effect I am looking for, but the behavior is consistent between light and dark modes.

Light Mode Example. The custom view is at the bottom with lightyellow background:

In Dark Mode, the controls inside the view inherit the background color, making the view unusable.

Borders are consistent though barely noticeable.

Bob made a good suggestion to try switching tabs to make sure everything is redrawn when switching between light & dark modes. But sadly, that wasn’t the issue (redrawing makes no diff) :cry:

Did it fix the default line edit widget color at least?

1. Yep, the QLineEdit widgets are OK after switching tabs.

2. Another idea: maybe a colored vertical bar in lieu of background color:

image

1 Like

I like the vertical bar!

On my macbook pro

Dark mode

Light mode

Looks great and you can put a tooltip on the widget to say what the color means.