On Mac and Gnome, native applications use an application preferences dialog that immediately applies the chosen settings as they are selected. On Windows and (I think) KDE, preferences are applied only when an "Apply" or "OK" button is pressed.
Are there any built-in Qt goodies to do this for you, or do you have to include several #ifdef
's in the dialog code to handle this (Q_WS_WIN
, Q_WS_MAC
, Q_WS_X11
)?
If you have done something like this before (even using #ifdef
's), could you share skeleton code as to how you pulled it off?
QSettings is a cross-platform abstraction that can be used for saving preferences, so hopefully that obviates the use of
#IFDEFs
I also found that it has really good performance. So good, in fact, that I just installed an event listener and called
save()
upon every single event.The form's class contains an event filter like this:
And my
save()
method looks like this:So, yes, you have to do some leg-work yourself to get your prefs saved immediately - but I didn't find it too arduous.
And although it (still) feels a bit ham-fisted to spray out save()s on every event,
QSettings
fine performance made this operation undetectable to the user.Writing a small class which enumerates every widget on a form and saves/restores each of its properties in
QSettings
would also be neat. This might be appropriate if you have some some tens/hundreds of preferences. I'll post back here when I've done it.Looks like you have to spin your own. Here are the important parts of our solution. This could probably be generalized if someone is so inclined. I'm also able to assume certain things because of our business rules that may break other applications. The toggle is a macro that can be defined at compile-time:
YOUR_APP_APPLY_PREFERENCES_IMMEDIATELY
preferences_dialog.h
preferences_dialog.cpp