Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with QMacNativeWidget and QApplication::setPalette()



  • Hi,

    I am trying to integrate a Qt widget as part of a plugin for an application I have no control over, and especially over its event loop. I've tried to follow the sample code at examples/widgets/mac/qmacnativewidget, but it only gets me so far.

    The widget is created and placed correctly, but when I try to set the palette using QApplication::setPalette() to be consistent with the rest of the application nothing happens. Setting the palette of individual widgets does work, though.

    I've created a small GitHub repository at https://github.com/sterin/qmacnativewidget-setpalette-problem with a simplified example and a similar pre-Qt example that works as expected.

    Thanks in Advance!



  • Update: The reason changes to the application palette do not affect QMacNativeWidget is that its constructor sets the palette explicitly. Once the palette is set explicitly, changes to the application palette no longer propagate through the widget.

    The simple solution is to just reset the palette to the default palette

    setPalette( QPalette() );
    

    Once this is done, change to the application palette start affecting the widget and its children.

    [edit: fixed class name SGaist]


Log in to reply