Results 1 to 11 of 11

Thread: Focus bug in windows

  1. #1
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Focus bug in windows

    Hello,

    I'm desperate with tab order.

    Qt Designer's tab order editing won't function for custom widgets (they show up as a single widget). I got nowhere using QWidget::setTabOrder. So I decided to re-implement focusNextPrevChild (build a QList of widget*, run through the list and do setFocus()) in a class and call it from my windows.

    It works fine on Linux. The problem is: windows XP just won't paint the focus, but it's there (e.g. if I hit spacebar the button will click). Tried a lot of work-arounds and I'm very frustrated.
    The funny thing is, I created an empty form with some buttons and tried setFocus() with no success. But after I hit tab and Qt changes and paint focus, setFocus() will paint correctly.

    What's the method Qt uses for giving focus to a widget?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Focus bug in windows

    Hi. Check the focusPolicy of your custom widget.
    J-P Nurmi

  3. #3
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Focus bug in windows

    Quote Originally Posted by jpn View Post
    Hi. Check the focusPolicy of your custom widget.
    Already did.
    Even set focusPolicy on each of the 3 buttons of my custom widget on the constructor, it still won't work.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Focus bug in windows

    Quote Originally Posted by zerobala View Post
    Qt Designer's tab order editing won't function for custom widgets (they show up as a single widget).
    Are we talking about promoted custom widgets or did you write a designer plugin for the custom widget?

    The funny thing is, I created an empty form with some buttons and tried setFocus() with no success. But after I hit tab and Qt changes and paint focus, setFocus() will paint correctly.
    Does the problem exists in Designer only?
    J-P Nurmi

  5. #5
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Focus bug in windows

    Quote Originally Posted by jpn View Post
    Are we talking about promoted custom widgets or did you write a designer plugin for the custom widget?


    Does the problem exists in Designer only?
    I wrote a designer plugin.

    No, the problem shows when I try to use setFocus() in my application (only in windows). But it's not exclusive to custom widgets.
    The fact is, an empty form with two buttons, the click slot of the first connected to setFocus() on the second and this won't paint the focus in Windows XP. But if I tab through the widgets and just one button-like focus (the "focus frame" like in the checkbox) is painted, then setFocus() will work correctly.

    Sorry if my english is bad, I'm brazilian

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Focus bug in windows

    Quote Originally Posted by zerobala View Post
    The fact is, an empty form with two buttons, the click slot of the first connected to setFocus() on the second and this won't paint the focus in Windows XP. But if I tab through the widgets and just one button-like focus (the "focus frame" like in the checkbox) is painted, then setFocus() will work correctly.
    Could you attach such example, please? I'd like to take a look.
    J-P Nurmi

  7. #7
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Focus bug in windows

    Quote Originally Posted by jpn View Post
    Could you attach such example, please? I'd like to take a look.
    Button "apply" should paint focus on "cancel" and vice-versa, but they'll work properly only after focus is painted on one of the buttons via tab.
    Attached Files Attached Files

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Focus bug in windows

    Looks like windows style implementation actually has a check that the button focus is only drawn when focus has been changed with the keyboard (tab, backtab, or shortcut), in other words, when attribute Qt::WA_KeyboardFocusChange is set. This can't even be worked around by passing appropriate focus reason (which I suspected to solve the problem at first sight)
    Qt Code:
    1. btCancel->setFocus(Qt::TabFocusReason);
    To copy to clipboard, switch view to plain text mode 
    One would have to set the attribute to the top level window by hand. I'm afraid I cannot recommend such workaround because it could break something else. Here it goes anyways
    Qt Code:
    1. window()->setAttribute(Qt::WA_KeyboardFocusChange);
    2. btCancel->setFocus();
    To copy to clipboard, switch view to plain text mode 
    You can always send a bug report to Trolltech if you feel it should behave differently.

    Edit: Oh, and there is another way to work it around I forgot to mention. A custom style which returns true for QStyle::styleHint(QStyle::SH_UnderlineShortcut).
    Last edited by jpn; 10th December 2007 at 12:26. Reason: updated contents
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    zerobala (10th December 2007)

  10. #9
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Focus bug in windows

    Quote Originally Posted by jpn View Post
    Looks like windows style implementation actually has a check that the button focus is only drawn when focus has been changed with the keyboard (tab, backtab, or shortcut), in other words, when attribute Qt::WA_KeyboardFocusChange is set. This can't even be worked around by passing appropriate focus reason (which I suspected to solve the problem at first sight)
    Qt Code:
    1. btCancel->setFocus(Qt::TabFocusReason);
    To copy to clipboard, switch view to plain text mode 
    One would have to set the attribute to the top level window by hand. I'm afraid I cannot recommend such workaround because it could break something else. Here it goes anyways
    Qt Code:
    1. window()->setAttribute(Qt::WA_KeyboardFocusChange);
    2. btCancel->setFocus();
    To copy to clipboard, switch view to plain text mode 
    You can always send a bug report to Trolltech if you feel it should behave differently.

    Edit: Oh, and there is another way to work it around I forgot to mention. A custom style which returns true for QStyle::styleHint(QStyle::SH_UnderlineShortcut).
    Thank you for your help!

  11. #10
    Join Date
    Dec 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Focus bug in windows

    Oops, it's not working for toolbuttons on default XP theme, same problem. Any suggestion?

  12. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Focus bug in windows

    Quote Originally Posted by zerobala View Post
    Oops, it's not working for toolbuttons on default XP theme, same problem. Any suggestion?
    I guess this is specific to WinXP. It seems that QToolButton does not draw any focus rect at all on WinXP. Try your app with old windows-style ("myapp.exe -style windows") and it will.

    PS. Sorry for late response. I was in hurry and totally forgot this..
    Last edited by jpn; 21st December 2007 at 20:54.
    J-P Nurmi

Similar Threads

  1. Windows focus / Windows Shutdown Problems
    By December in forum Qt Programming
    Replies: 6
    Last Post: 22nd October 2007, 14:10
  2. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09
  3. Tab/Enter focus problem
    By b1 in forum Qt Programming
    Replies: 4
    Last Post: 23rd October 2006, 23:34
  4. Replies: 5
    Last Post: 4th August 2006, 23:44
  5. Replies: 2
    Last Post: 24th July 2006, 18:36

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.