Results 1 to 3 of 3

Thread: Raise window to top and give it focus

  1. #1
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Raise window to top and give it focus

    I've got a program with 2 windows that are open. When I programmatically change the window that's on top, it doesn't have focus.

    Qt Code:
    1. SecondWindow->raise();
    2. SecondWindow->setFocus();
    To copy to clipboard, switch view to plain text mode 

    The second window comes to the top, but doesn't have focus
    Since I'm working in windows if I add

    Qt Code:
    1. HWND WinHandle = (HWND)SecondWindow->winID();
    2. SetFocus(WinHandle);
    To copy to clipboard, switch view to plain text mode 

    It gets focus. Is there a way to do it using strictly Qt?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Raise window to top and give it focus

    That the window does not get the focus is clear as the docs state:
    Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window.
    And the reason you want to give the focus to the window is precisly because it is NOT the current active window.

    Try calling QWidget::activateWindow() on the window you want to make active.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    TonyInSoMD (8th August 2017)

  4. #3
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Raise window to top and give it focus

    I could have sworn I had already tried that and it didn't work, but it does now. Thanks.

Similar Threads

  1. Replies: 1
    Last Post: 20th February 2017, 15:22
  2. Replies: 6
    Last Post: 21st August 2013, 13:53
  3. layout in widget give me an empty window!
    By rimie23 in forum Qt Programming
    Replies: 20
    Last Post: 5th June 2012, 19:59
  4. QProcess, how to give focus to the new process on Mac
    By simlab in forum Qt Programming
    Replies: 3
    Last Post: 25th January 2010, 00:27
  5. Window focus issues (How to force focus to a window?)
    By montylee in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2009, 02:00

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.