Solved Unwanted delay when switching focus between MainWindow and non-modal dialog window
-
Hi,
It's just a small thing, but I am facing the following situation.I have a main app window with 4 of
QTreeViews
, one of which contains aQFileSystemModel
.Then there is a situation where I need to open a dialog window in a non-modal way, such that I can change the current row selection in one of the
QTreeViews
.However, I have noticed that there is a small, but noticeable delay when switching between the MainWindow window and the dialog window. This delay is for example clearly noticeable when I click/drag on the respective window's title bar to move it: it would initially not seem to react, and then snap to the current mouse position to follow the cursor's movement.
Although not critical, I find this delay somewhat user unfriendly, and was wondering what the underlying causes might be. After all, when switch-drag-moving between the main app window and the Qt Creator for example, this noticeable delay does not occur. So why would it occur between the Main window and the dialog window?
Any insights provided will be greatly appreciated!
-
@Diracsbracket On what OS? Which Qt version? Is your app doing any heavy calculations? ...?
-
@Diracsbracket
After you have answered @jsulm's questions...We may need to see your code. For example, if there is any way that when changing windows (or something you do in the modeless window) causes your main app window to re-read the file system to re-populate the
QFileSystemModel
'sQTreeView
that might lead to the delay.... -
@jsulm said in Unwanted delay when switching focus between MainWindow and non-modal dialog window:
On what OS? Which Qt version? Is your app doing any heavy calculations?
Hi @jsulm. My system detail (as per Qt Creator's Help | System Information):
Qt 5.9.2 (i386-little_endian-ilp32 shared (dynamic) release build; by MSVC 2015) on "windows" OS: Windows 7 SP 1 (6.1) [winnt version 6.1.7601] Architecture: x86_64; features: SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 AVX
No heavy calculations are performed. Before opening the dialog, signal/slot connections related to selection change in the tree view are disconnected, and also all models have been populated at that point.
I have an
eventFilter
installed on several objects, among which the viewports of the QTreeViews.If I activate the debug lines in my
eventFilter
, as follows:bool MainWindow::eventFilter(QObject *obj, QEvent *event) { const QEvent::Type type = event->type(); qDebug() << "event: " << type << obj->objectName() << obj->parent()->objectName(); ... }
I get the following output upon click-dragging the main window (with previously the dialog being active) (the
WindowDeactivate
event stems from the app losing focus when I copied the output below from Qt's Debug output):event: QEvent::Type(WindowActivate) "qt_scrollarea_viewport" "scriptTree" event: QEvent::Type(WindowActivate) "qt_scrollarea_viewport" "fileTree" event: QEvent::Type(WindowActivate) "" "qt_scrollarea_hcontainer" event: QEvent::Type(WindowActivate) "qt_scrollarea_viewport" "" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "scriptTree" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "fileTree" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "" event: QEvent::Type(Paint) "" "qt_scrollarea_hcontainer" event: QEvent::Type(DynamicPropertyChange) "" "qt_scrollarea_hcontainer" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "scriptTree" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "fileTree" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "" event: QEvent::Type(WindowDeactivate) "qt_scrollarea_viewport" "scriptTree" event: QEvent::Type(WindowDeactivate) "qt_scrollarea_viewport" "fileTree" event: QEvent::Type(WindowDeactivate) "" "qt_scrollarea_hcontainer" event: QEvent::Type(WindowDeactivate) "qt_scrollarea_viewport" "" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "scriptTree" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "fileTree" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "" event: QEvent::Type(Paint) "" "qt_scrollarea_hcontainer" event: QEvent::Type(DynamicPropertyChange) "" "qt_scrollarea_hcontainer" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "scriptTree" event: QEvent::Type(Paint) "qt_scrollarea_viewport" "fileTree" event: QEvent::Type(Paint) "qt_scrollarea_viewport" ""
I have added trace lines like the one below in all my functions:
qDebug() << Q_FUNC_INFO;
None of the other functions' traces appear in the debug output above, so no calculations are performed by my code before/after the switch from dialog to MainWindow.
-
@JonB Thanks for reacting!
There is nothing that causes the data in the various treeviews to be updated upon switching windows, as myqDebug()
trace output in the post above shows (theseqDebug()
trace statements are in virtually all my functions).What is also obvious is that when switching, the menu bar of my main window is slow to getting disabled/enabled again. The window title and frame however, are activated immediately upon clicking.
-
Since my old laptop died, and I moved to a new one using Windows 10, etc... the delay is basically gone, or is small enough not to be noticed. Don't know if it was because I have a more powerful machine now, or because I changed to 5.9.4 or Windows 10, or all of it. So I'll close this thread.