Focus stealing progress dialog
-
I have a progress dialogue as shown above. Whenever it updates its contents, it steals Focus which is most anti-social.
I changed the code to add:
// // Set the window so that it does not take focus // setAttribute(Qt::WA_ShowWithoutActivating);
as it appeared that this might prevent that happening, but unfortunately it still misbehaves.
What do I need to change to stop this focus thief :)?
Thanks
David -
Hi,
You seem to have multiple progress bars so likely a custom dialog, am I correct ?
Do you update only the progress bar or is something else happening ?
Did you made Cancel the default button ? -
Yes, very much a custom dialogue. And yes, the Cancel button has the "autoDefault" attribute set. The code that updates the progress bars is driven by two member functions, Progress1, and Progress2:
void ProgressDlg::Progress1(const QString& text, int achieved) { QMetaObject::invokeMethod(this, "slotProgress1", Qt::AutoConnection, Q_ARG(const QString&, text), Q_ARG(int, achieved)); } void ProgressDlg::Progress2(const QString& text, int achieved) { QMetaObject::invokeMethod(this, "slotProgress2", Qt::AutoConnection, Q_ARG(const QString&, text), Q_ARG(int, achieved)); }
which can be driven from non-UI threads. Those slots just do some book-keeping, update the text fields and the sliders, and finally invoke QCoreApplication::processEvents(); which I am told was found necessary to ensure the progress dialogue was updated properly (no I didn't write this code). They do call raise(), but do not call (e.g.) setFocus(). The only time setFocus() is used is when the dialogue is initially created.
-
Would it be possible to share the implementation of the dialog ?
-
@SGaist Certainly:
https://www.dropbox.com/scl/fo/yzyyeijwip3pil9poly4p/ALZGlamwAtpuC5NrqMfkTUg?rlkey=4r29ofptuf5zzqdia027av71s&dl=1PS Removing autoDefault from the Cancel button changed nothing.
PPS Same problem on both Windows and macOS
PPPS If a shared debug session would help you will be welcome to connect to my system using e.g. Chrome Remote Desktop -
Nothing obvious jumps to my eyes.
Would it be possible to have the same dialog but buildable so I can test it on my machine ?