PDA

View Full Version : Keyboard and Mouse focus when having several windows...



pir
24th July 2006, 14:15
Hi!
The thing is that I don't really understand how to handle the keyboard and mouse. I think this is reffered as focus or something...

My program consists of a main window containing a 3d scene. The user can open other windows that displays information about the scene and selected components of it. No of the windows is set to modal ( no window freeze the others ) or what it's called.

If the user have opened on of the additional windows, we'll call it window A and has the main window, window M, in focus there are no problem when handling keyboard and mouse input. M takes both the mouse and keyboard. But if I have A in focus and I then want to spin the scene in the M window by holding down Ctrl and drag the mouse over it, the Ctrl is catched by the A window ( which also uses it ) and only the mouse is catched by M.

Whats happeing is that when I move the mouse over to the M window and pressing Ctrl , the A window catches that and then when the mouse is dragged over the M window it can't register any Ctrl pressed... because A has already taken care of it, in the wrong way.

So I wonder if there is any way to let the Window that lies under the current position of the mouse also catch the keyboard input, or something similar? Maybe that solution would lead to some other anyoing things... like if I want to type text in a window but places the mouse pointer over another window after selecting the textfield which is supposed to be filled...

Or do I need some kind of administrator interpreting the combinations of events that is sent from the mouse and keyboard. If so, how do I implement something like that?

thanks for reading
pir

munna
24th July 2006, 14:22
You can proabably use enterEvent() and leaveEvent() and set the focus of your widgets accordingly.

pir
24th July 2006, 18:36
Yes, that seems like something to start with. But there are some problems with how to interpret the events. The problem is that there can be more than one window that can accept a Ctrl key. I have a tree view of the object in one window and the 3d scene in the other. If I hold down Ctrl and drag my mouse around the 3d scene window, it results in turning the camera. But if I selects items in the tree view with the Ctrl key pressed several items is selected.

So if I press the Ctrl key and move the mouse to the 3d scene, it should know that the Ctrl is pressed down. But it's pressed down before the mouse have reached the window, so it will miss the event, because it's handeled by another window where it results in nothing... is there any way to see if the Ctrl key is held down in Qt or do I need to do this myself?

thanks
pir