Results 1 to 9 of 9

Thread: activateWindow() doesn't work

  1. #1
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default activateWindow() doesn't work

    Hello!
    I have two windows - the main one and the secondary window (an image viewer). Here is a code demostrating how I show the image viewer window:

    Qt Code:
    1. if (! img_viewer->window.isVisible()) //if the viewer is not visible
    2. {
    3. img_viewer->window.show();
    4. activateWindow(); //trying to set focus back to the main window
    5. }
    6. img_viewer->set_image (full_path); //just show an image
    7. //at the QLabel
    To copy to clipboard, switch view to plain text mode 

    So the focus works in the following way:
    1. When the image viewer window became visible (after the show() method), the focus moves to this image viewer window.
    2. But I want to get the focus back into the main window. So I call activateWindow().
    3. Nothing happens. The focus stays on the image viewer window.

  2. #2
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: activateWindow() doesn't work

    What if you also call QWidget::setFocus() on a widget in your main window?

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: activateWindow() doesn't work

    try to do like this
    Qt Code:
    1. ...
    2. raise();
    3. activateWindow();
    4. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: activateWindow() doesn't work

    Yes, I've tried raise(), and setFocus for the widget, etc - nothing changed, focus stays on the secondary window until I click on the main window.
    Now I have found a bad solution:
    Qt Code:
    1. img_viewer->window.show();
    2. hide();
    3. show();
    To copy to clipboard, switch view to plain text mode 
    After that, the focus moves to the main window. But I want to move the focus without any window disappearing

  5. #5
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: activateWindow() doesn't work

    Are you testing this on Linux? I've seen cases were raise() did not have any effect. Does it help if you turn "desktop effects" off?

  6. #6
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: activateWindow() doesn't work

    Yes, I'm on Linux, Qt 4.4.3. Desktop effect are turned off. Soon I'll test this focusing problem on Windows XP.

  7. #7
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: activateWindow() doesn't work

    Update.
    When I'm calling hide() and show() for the main window (after the image viewer window becomes active), I get those errors at console output:

    X Error: BadWindow (invalid Window parameter) 3
    Major opcode: 20 (X_GetProperty)
    Resource id: 0x16055ff
    X Error: BadWindow (invalid Window parameter) 3
    Major opcode: 15 (X_QueryTree)
    Resource id: 0x16055ff
    X Error: BadWindow (invalid Window parameter) 3
    Major opcode: 40 (X_TranslateCoords)
    Resource id: 0x16055ff

    So the problem is in the X-system?

  8. #8
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: activateWindow() doesn't work

    Could you make a minimal compilable example-program demonstrating the problem and post it here?

  9. #9
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: activateWindow() doesn't work

    I'll post an example a bit later. Currently I've solved the problem calling setWindowFlags (Qt::Tool) for the secondary window.

Similar Threads

  1. signal of QListWidget doesn't work
    By vito49 in forum Qt Programming
    Replies: 10
    Last Post: 1st October 2008, 05:07
  2. Qt4 : QPainter::setRedirected doesn't work
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2008, 17:52
  3. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  4. Change work area OS
    By pakulo in forum Qt Programming
    Replies: 15
    Last Post: 15th May 2007, 07:20
  5. QTextEdit Justify align making work
    By dec0ding in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 12:02

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
  •  
Qt is a trademark of The Qt Company.