PDA

View Full Version : Managing widget focus behaviour



mnemonic_fx
7th February 2008, 04:23
I'm using Qt 4.3.3 on Xcode. I need to know a way to prevent a parent widget to keep on showing & focusing itself, when a child widget is closed.

Example:

I have one QWidget, and 2 QDialog as a child of QWidget.
In some cases a user could open one of the QDialog (let's call it dialogOne), and when dialogOne is showed, a user open dialogTwo.

Based on what I have been coded, the last shown dialog takes top position (the window is activated). But when I close the top dialog (either dialogOne or dialogTwo), the focus is moved to the main QWidget (the parent).

Now, what I want to do is to make a focus behaviour based on least recently focused widget / dialog. So for example:

If the order of widget is (bottom to top in Z-axis): parentWidget->dialogOne->dialogTwo.

When I close dialogTwo, the order is:
parentWidget->dialogOne.

If the order of widget is (bottom to top in Z-axis): parentWidget->dialogTwo->dialogOne.

When I close dialogTwo, the order is:
parentWidget->dialogTwo.

Is there anyone that could help me on this issue ? :)

jpn
7th February 2008, 09:54
Well, that's the natural an expected behavior. You can


dialogOne->raise();
dialogOne->activateWindow();

yourself if you want to behave it differently.

mnemonic_fx
7th February 2008, 10:20
I don't think it's a natural behavior from the point of view of user on Mac OS X.
If I observe other apps (probably using Cocoa), the closing of one window doesn't activate the main window, but it activates the most recent focused window.

Well, the problem with your suggestion is I need to do that manual activation on all dialogs.

Should I do something in another way ?
Like not making dialogOne & dialogTwo a child of the QWidget ?

Which is the best parent for all widgets ?

wysota
7th February 2008, 10:27
You should wait for 4.4. As far as I know (I might be wrong though) it respects the focus order on Mac. You might try one of the snapshots and see if it works. If it doesn't then it means the observed behaviour is expected. Make sure you are using modal dialogs and the parent-child relationship is correct.