PDA

View Full Version : Qt 3 : focusInEvent (QFocusEvent * e)



xplizion
2nd March 2006, 09:34
Hi,

when I use this method and ask for the reason it always seems to give me the same reason:
QFocusEvent::ActiveWindow

now when I look at the doc I see there are several reasons, why make these when I always receive the same ones :D (if I alt+tab, click, or click another window)

Does anyone know how to solve this?

focuspolicy is set to strongfocus

Grtz and TIA

Xplizion

wysota
2nd March 2006, 09:53
Did you read info about focus in Qt (http://doc.trolltech.com/3.3/focus.html)?

xplizion
2nd March 2006, 10:00
Yes I have and particularly this part

The User clicks a widget (http://doc.trolltech.com/3.3/focus.html#1-2)

so normally when the user clicks a widget it sends an QFocusEvent to focusInEvent and it does but it always sends as reason activeWindow...

wysota
2nd March 2006, 10:05
Remember that those reasons correspond to both focus in and focus out. If you click on a widget, you're making it active, so the reason is obvious. "Tab" will probably be if you start iterating widgets in a window using tab key. The same with "Backtab". "Popup" and "Shortcut" seem obvious too, although maybe not every platform uses them? Hard to say. You can set the reason yourself if you post events to the queue, too.

Now you know something ;)

xplizion
2nd March 2006, 10:11
hmm thx
but I still have no idea how to solve my problem...



void vgui_qt_adaptor::focusInEvent (QFocusEvent * e)
{


switch(QFocusEvent::reason())
{
case QFocusEvent::Mouse : vcl_cout << "Mouse" << vcl_endl; break;
case QFocusEvent::Tab : vcl_cout << "Tab" << vcl_endl; break;
case QFocusEvent::Backtab : vcl_cout << "Backtab" << vcl_endl; break;
case QFocusEvent::ActiveWindow : vcl_cout << "ActiveWindow" << vcl_endl; break;
case QFocusEvent::Popup : vcl_cout << "Popup" << vcl_endl; break;
case QFocusEvent::Shortcut : vcl_cout << "Shortcut" << vcl_endl; break;
case QFocusEvent::Other : vcl_cout << "Other" << vcl_endl; break;
}
}


I tried it this way and last time I ran it says activeWindow all the time except 3 times... 3 times it says mouse, and I wasn't doing anything else, just clicking around :)

now the problem is I need to make a distinction between when the user clicks a window and when the mainwindow is clicked (so the mainwindow hides the little windows :) which also sends a focusInEvent )

(btw I'm using Qt together with vxl)

wysota
2nd March 2006, 10:15
I need to make a distinction between when the user clicks a window and when the mainwindow is clicked

Could you explain that?

xplizion
2nd March 2006, 10:20
well, the mainwindow spawns 2 small windows with pictures in them (like a very artificial MDI :) ), now when 1 of the little windows is clicked I need to set this picture as "active" in the mainwindow so the mainwindow knows on which image it should do the processing.

When I click the little windows it does this perfectly, it sets the things as active.

but when I click my menu in the mainwindow it minimizes (hides?) the little windows and by doing this it again sets focus to 1 of the little windows thus messing up my entire plan :)

I hope you understand
thx for trying to help me out ;)

xplizion
2nd March 2006, 11:43
k it seems to be fixed

gonna do some testing but this is what I did

I just dropped the whole focusInEvent method and used windowActivationChange instead



void vgui_qt_adaptor::windowActivationChange (bool oldActive)
{
if(!oldActive)
{
//-- Do something with the event here -> FocusGained
}
else
{
//-- Do something with the event here -> FocusLost
}
}


this seems to do the job much better then the focusInEvent

thx to wysota for trying to help me anyways ;)

grtx Xplizion

wysota
2nd March 2006, 14:36
I just dropped the whole focusInEvent method and used windowActivationChange instead


That's exactly what I was going to suggest :)