PDA

View Full Version : Focus and interact with a QDockWidget and the MainWindow separately.



LucaDanieli
5th February 2017, 19:46
I have created an application which consists of one MainWindow (containing a text-editor) and optional additional windows (QWidgets, containing additional text-editors).

The MainWindow is provided with a Dock which lists the available documents opened within the project, and highlights in the list the document currently selected.

The only problem is that when I focus an additional window and I then click on the floating dock, the MainWindow gets focused. I would like therefore to be able to focus a floating dock separately, but I have no idea on how to separate the focus of the main window from the focus of the dockWidget.

Also, I guess that when I click on a Dock, the application reacts as if I clicked the MainWindow. I would like then the MainWindow to be unawared whether the Dock is clicked or not (when the dock is undocked).

Does somebody have any idea?

anda_skoa
6th February 2017, 09:12
I am not sure I fully understand what you are looking for, but are you currently somehow tracking focus to determine which document is selected?

Cheers,
_

d_stranz
6th February 2017, 22:41
I would like therefore to be able to focus a floating dock separately, but I have no idea on how to separate the focus of the main window from the focus of the dockWidget.

Perhaps you don't understand what "focus" means. In a windowing system, for a window to have the "focus" means that all user interaction goes to that window for handling - like keystrokes, mouse clicks, etc. If two windows simultaneously could have the focus, it would mean that any typing or mouse clicks you did would go to both of the windows at the same time. That would make no sense at all. Only one window can have the input focus at any time.

So what is it you really want to do? Somehow indicate to the user which document is the active document even if that document's window does not have the input focus?

LucaDanieli
6th February 2017, 23:10
I see.
I am sorry.
What I would like is to click on a floating QDockWidget without having the all MainWindow to come up in front (covering other visible Widgets).

d_stranz
7th February 2017, 16:45
I don't understand your UI. Do you mean to say that you have a MainWindow with dock widgets, menu., toolbars, etc. and you also have a set of independent top-level windows floating on screen at the same time?

Maybe you can try to pass the Qt::WindowStaysOnTopHint to QWidget::setWindowFlags(), but I do not know if you can change this dynamically (in other words, set and unset the flag for a particular widget on the fly).

Another option would be to use QMdiArea as the central widget of your MainWindow and add all of your document windows to that as children. Then, your main window would always be below your document windows.