1
votes

Problem

Windows has a system setting that will cause the mouse pointer to jump (move) to a new focus element automatically, e.g. the default button of a dialog that pops up. While the advantage is an increase in speed and a reduction of mouse movements, it has a disadvantage:

If this happens just when before the user clicks on another element, the user is unable to abort his/her action in time and will immediately accept the dialogs default button because the focus is moved by the system. Usually this may entail cumbersome work to retrace the steps up to this point (think a file chooser dialog that forgot the very long path you input previously) but it could also mean triggering an irreversible process (e.g. file deletion).

Aim

Essentially I would like to disable the dialog's inputs for a small amount of time, just enough to prevent an inadvertant mouse click or keyboard button press.

Question

It comes down to a C++ question, namely how to access the base classes' objects (GUI widgets) from the inheriting class, i.e.

  1. disable the button widgets of a QMessageBox
  2. start a single shot QTimer and connect it to a slot that
  3. enables the previously disabled widgets

(As alternative, I probably could reimplement input event handlers that suppress all input for a specific amount of time, but although I intend to keep that time very short (e.g. 100 ms), the user is not informed of the disabled input using that method.)

A simple class derived from QDialogBox can be found at http://www.qtforum.org/article/24342/messagebox-auto-close-mouse-event-close.html.

2

2 Answers

3
votes

Do you need to use one of the "native"-ish message boxes provided by the QMessageBox static functions?

Otherwise, that's pretty simple to achieve, by building a QMessageBox and adding standard buttons to it:

QMessageBox *messageBox = new QMessageBox;
QPushButton *okButton = messageBox->addButton(QMessageBox::Ok);
okButton->setEnabled(false);
// use a QTimer to add logic to reenable the button
// use QCursor to move the mouse cursor on the button 
// add a nice countdown in the button's label, like Firefox does
// add other nice UX touches as wanted

Last points are left as an exercise to the reader :)

0
votes

To en/disable the buttons in QMessagebox one would need access to them.

qmessagebox.cpp uses buttonBox = new QDialogButtonBox; and the addButton() method

d->buttonBox->addButton(button, (QDialogButtonBox::ButtonRole)role);
d->customButtonList.append(button);

But I don't understand Qt internals and am unable to find these in qmessagebox.h and thus fail to find out if there is a chance to access the buttons..