Results 1 to 9 of 9

Thread: Qt 3 : focusInEvent (QFocusEvent * e)

  1. #1
    Join Date
    Mar 2006
    Posts
    7
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt 3 : focusInEvent (QFocusEvent * e)

    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 (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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt 3 : focusInEvent (QFocusEvent * e)

    Did you read info about focus in Qt?

  3. #3
    Join Date
    Mar 2006
    Posts
    7
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 3 : focusInEvent (QFocusEvent * e)

    Yes I have and particularly this part

    The User clicks a widget

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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt 3 : focusInEvent (QFocusEvent * e)

    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

  5. #5
    Join Date
    Mar 2006
    Posts
    7
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 3 : focusInEvent (QFocusEvent * e)

    hmm thx
    but I still have no idea how to solve my problem...

    Qt Code:
    1. void vgui_qt_adaptor::focusInEvent (QFocusEvent * e)
    2. {
    3.  
    4.  
    5. switch(QFocusEvent::reason())
    6. {
    7. case QFocusEvent::Mouse : vcl_cout << "Mouse" << vcl_endl; break;
    8. case QFocusEvent::Tab : vcl_cout << "Tab" << vcl_endl; break;
    9. case QFocusEvent::Backtab : vcl_cout << "Backtab" << vcl_endl; break;
    10. case QFocusEvent::ActiveWindow : vcl_cout << "ActiveWindow" << vcl_endl; break;
    11. case QFocusEvent::Popup : vcl_cout << "Popup" << vcl_endl; break;
    12. case QFocusEvent::Shortcut : vcl_cout << "Shortcut" << vcl_endl; break;
    13. case QFocusEvent::Other : vcl_cout << "Other" << vcl_endl; break;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    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)

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt 3 : focusInEvent (QFocusEvent * e)

    Quote Originally Posted by xplizion
    I need to make a distinction between when the user clicks a window and when the mainwindow is clicked
    Could you explain that?

  7. The following user says thank you to wysota for this useful post:

    xplizion (2nd March 2006)

  8. #7
    Join Date
    Mar 2006
    Posts
    7
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 3 : focusInEvent (QFocusEvent * e)

    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

  9. #8
    Join Date
    Mar 2006
    Posts
    7
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 3 : focusInEvent (QFocusEvent * e)

    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

    Qt Code:
    1. void vgui_qt_adaptor::windowActivationChange (bool oldActive)
    2. {
    3. if(!oldActive)
    4. {
    5. //-- Do something with the event here -> FocusGained
    6. }
    7. else
    8. {
    9. //-- Do something with the event here -> FocusLost
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    this seems to do the job much better then the focusInEvent

    thx to wysota for trying to help me anyways

    grtx Xplizion

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt 3 : focusInEvent (QFocusEvent * e)

    Quote Originally Posted by xplizion
    I just dropped the whole focusInEvent method and used windowActivationChange instead
    That's exactly what I was going to suggest

Similar Threads

  1. QLineEdit and focusInEvent
    By fuzzywuzzy01 in forum Qt Programming
    Replies: 5
    Last Post: 16th August 2007, 23:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.