Dark look and feel in qt apps

I’m building an engine that lives inside a qt app that we built.
The qt style of the app and shotgun don’t work well together.

I tried calling _initialize_dark_look_and_feel() and that fixes the shotgun widgets but it also applies the shotgun style to the rest of the qt app, which I don’t want.

I tried copying __initialize_dark_look_and_feel_qt5() into a function that I could pass a widget in to style but it doesn’t seem to do anything.

Are there any ideas on how to get this to work or other ways to get the shotgun style to only affect the shotgun widgets?

    def set_qt_style_on_widget(self, widget):
        """
        Applies a dark style for Qt5 environments. This sets the "fusion" style
        at the application level, and then constructs and applies a custom palette
        that emulates Maya 2017's color scheme.
        """
        widget.setStyle(self.style)
        widget.setPalette(self.palette)
        widget.setStyleSheet(".QWidget { font-size: 11px; }")

    def _init_pyside(self):
        """
        Handles the pyside init
        """
        from Qt import QtGui, QtWidgets
        self.style = QtWidgets.QStyleFactory.create('fusion')
        self.palette = QtGui.QPalette()
        # setup palette the same as __initialize_dark_look_and_feel_qt5

    def _create_dialog_with_widget(self, title, bundle, widget_class, *args, **kwargs):
        dialog, widget = super(CustomEngine, self)._create_dialog_with_widget(title, bundle, widget_class, *args, **kwargs)
        self.set_qt_style_on_widget(widget)
        return (dialog, widget)
3 Likes

It looks like QWidget.setStyle isn’t inherited by child widgets. I probably need to setup some sort of event to add the style anytime a new child widget is added.

2 Likes

Styling with Qt is an utter pain. Stylesheets can be used to apply styling for a widget and all its descendants, but setting a palette will affect the whole application. Your suggestion of an event might work, I’ve not tried that before.
Usually in an app where we don’t control the palette, and we inherit the look and feel of the parent application.

2 Likes

Setting style on the created widget and all of its children got me something halfway decent to look at.

I will need to try to figure out the event or try to look in to QProxyStyle and see if I can build something that switches properties based on some property on a parent widget.

1 Like