Skip to content

pyqtgraph does not use QPalette colors #1588

@irgolic

Description

@irgolic

Short description

pyqtgraph sets the background to white and text color to black. In example implementations of a dark mode, these are manually switched.

Qt uses QPalette to specify colors https://doc.qt.io/qt-5/qpalette.html#ColorRole-enum and automatically updates them when the style changes (e.g., Mac switching between light and dark mode).

Pyqtgraph should use QPalette colors by default, otherwise, dependencies have to manually propagate palette changes to pyqtgraph.

Code

The global QApplication instance exposes a paletteChanged signal. So essentially, you could include this snippet of code in any file that you know will be imported after the QApplication is created.

def updatePalette(palette):
    bg = palette.base().color().name()
    fg = palette.windowText().color().name()

    setConfigOption('background', bg)
    setConfigOption('foreground', fg)
QApplication.instance().paletteChanged.connect(updatePalette)

From my understanding, setting a config option like this only sets the default; it doesn't override a developer specifying a color like in pg.PlotWidget(background='w').

I'm unsure if setting a config option globally like this propagates the change to already created objects, but it at the very least sets the correct color initially.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions