[bt-devel] Switch QAction state without events

Jaak Ristioja jaak at ristioja.ee
Tue Apr 3 14:12:31 MST 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Patrick!

On 03.04.2012 23:46, Patrick Zimmermann wrote:
> I'm currently hunting a bug in session restore. Most actions in the
> view menu don't restore their state.
> 
> The problem I face now is that I need to switch the state of the
> QActions (to change them to what the config says) without
> triggering the events they are associated with. As far as I
> searched, QActions themselves don't provide a feature for this.
> 
> The three possible solutions that came to my mind are: 1.
> Disconnecting the QActions, switching their state and reconnecting
> again. 2. Put an if(actionsEnabled) {} in all functions the actions
> are connected with to allow temporarilly turning them of. 3. Check
> whether the QAction and reality are different and if yes call the 
> callback function manually once to get them in line before
> switching them to the correct state.
> 
> All three seem somewhat ugly to me. With the third being the best
> according to my taste. Are there any better ideas/typical
> approaches of doing this?

How about using QObject::blockSignals(bool), e.g. something like:

inline void setQActionCheckedNoTrigger(QAction * const action,
                                       const bool checked = true)
{
    Q_ASSERT(action);
    const bool signalsWereBlocked = action->blockSignals(true);
    action->setChecked(checked);
    action->blockSignals(signalsWereBlocked);
}

God bless!
Jaak
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)

iQgcBAEBAgAGBQJPe2e7AAoJELeXyoqzFNdN7pI//2ucM7Cr2dyD34jQLD0mHOlp
Xkr7xnQXdBa6gZrnsYmPYnwnu0RYJ/bB2Bbd61zwvyE3t03TIihTdSup80NOsIPh
n2bzRKQ9QFrmRiUfm/imqARvI9V0teA6rd/lkfDifZCxCA9sEZSM1h1Fmof6hyKL
a6Qzp78C0L4VXke88u/uCY8QUvysQn9s+BNEDcxrsOZ9o2e5tPtrP5L6lLVV5ShV
ll7FrjF9tHisdYtlNkbPrUgkk0GaaRT0OKsrENL+/o+gKjc4iowbg8hm3jf3Y6N8
XnjiWPrmMue/mAjacuylGmNw2wBr7q+F65tBNRtnmTauY049lzVrKqKtW0OSMZHh
tQTqh+fj81AWYt3yHdG+Tnu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