QDialogButtonBox accepts clicks outside the buttons ( but near to them )

  • I am using QDialogButtonBox for having the Ok-Cancel Buttongroup for my dialog. The application that is written is intended to run on both Mac and Windows. The layout of the buttons are coming correctly. But in Mac, even when I click somewhere outside the buttons the event related to the click on the nearest button is getting emitted.

    !http://i.stack.imgur.com/fc0Yr.png(Button Click get accepted when clicked outside the button)!

    When I checked the button boundaries by putting a stylesheet for the QPushButtons the buttons appear to be taking up additional space.

    !http://i.stack.imgur.com/Ij4PJ.png(Button layout after applying style sheet)!

    This is the code:

    @QDialogButtonBox * okCancelButtonBox = new QDialogButtonBox( this );
    mOKButton = new QPushButton( "OK", okCancelButtonBox );
    connect( mOKButton, &QPushButton::clicked, this, &MyDialog::Accept );

    mCancelResetButton = new QPushButton( "Cancel", okCancelButtonBox );
    connect( mCancelResetButton,&QPushButton::clicked, this, &MyDialog::Reject );

    okCancelButtonBox->addButton( mOKButton, QDialogButtonBox::AcceptRole );
    okCancelButtonBox->addButton( mCancelResetButton, QDialogButtonBox::RejectRole );

    dialogLayout->addWidget( okCancelButtonBox );@
    The QDialogButtonBox seems to be taking care of the button layout differences in Windows and Mac automatically. So I don't want to have my own layout to do those changes. Is there any way to avoid this false click events using QDialogButtonBox itself?

  • That, it seems, would be a wider problem than just QDialogButtonBox. QDialogButtonBox uses QPushButtons. That would suggest that the same problem should exist for other push buttons. Could you check that? (I don't have a Mac).

    In any case: please file a bugreport.

    As a workaround, perhaps you can use an event filter to manipulate which mouse events are passed through to the button. You might try to filter out clicks on buttons if the clicks are too close to the edge of the button widget. Getting the margin right will take some experimenting of course. If you install this filter on the application itself, and check if the object inherits QPushButton, you may be able to get away with a single filter instead of installing on all buttons individually.

  • Hi Andre,

    Thanks for the reply. I checked the behaviour with QPushButton. As you pointed out, I was able to see the issue there as well.

    I will raise a bug report.


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.