简体   繁体   中英

How to avoid Qt to execute QAbstractButton::nextCheckState() when checkable button is clicked?

When you click a checkable button. The checkstate always inverts:
on to off
off to on

This is because when a checkable button is clicked Qt calls the nextcheckstate function.

QAbstractButton::nextCheckState()

Is there a way to avoid that? (I would like to decide check state by myself)

In my mind I would have to do the following steps to avoid that:

  1. Create a MyPushButton Class which inherits QPushButton
  2. Declare in mypushbutton.h an override function which overwrites the function when a checkable button is clicked
  3. Somehow suppress calling QAbstractButton::nextCheckState() in that overriding function

Does somebody know which function to override?

Try:

Checkablebutton->blockSignals(true); // Maybe nextCheckState() is not call from now on until BlockSingls(false)

//some code

Checkablebutton->blockSignals(false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM