I'm busy creating a preferences dialog for my Qt application. The preference will just contain colour/theme settings for one of the widgets in my application which is used all over the place, i.e. many instance of the same widget at any one time. I would like to colour preferences to apply to each instance of the widget immediately when they are changed. I'm wondering how best to achieve this and if there is some accepted best practice for system wide preferences like this. I have a number of ideas for how to achieve this and they will probably all work, but some will definitely be messier than others.

One idea is to have a ColourManager widget which emits colourChanged(EColour, QColor) where EColour is some enum, e.g.

enum EColour {
COLOUR_SPECIAL_HIGHLIGHT_1 = 0,
COLOUR_SPECIAL_HIGHLIGHT_2,
COLOUR_ERROR_FOREGROUND,
...
}

As long as that signal gets to each widget that cares about colours then they could update their internal states accordingly and paint themselves with the correct colours.

The next question would be how best to hook up the colourChanged(EColour, QColor) with each widget that's interested in colours. I imagine that the QMainWindow would own the ColourManager and would also each of the widgets that might be interested in colours. So QMainWindow could connect the colourChanged signal to the relevant ColourChanged slots.

I am aware of QSettings and make use of it to store various application settings already. Another idea would be to write colour changes to QSettings and then have other widgets read settings from QSettings.

If you've tackled this before or have any ideas, please let me know.

Thanks
Stefan