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:
Code:
if (! img_viewer->window.isVisible()) //if the viewer is not visible
{
img_viewer->window.show();
activateWindow(); //trying to set focus back to the main window
}
img_viewer->set_image (full_path); //just show an image
//at the QLabel
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.
Re: activateWindow() doesn't work
What if you also call QWidget::setFocus() on a widget in your main window?
Re: activateWindow() doesn't work
try to do like this
Code:
...
raise();
activateWindow();
...
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:
Code:
img_viewer->window.show();
hide();
show();
After that, the focus moves to the main window. But I want to move the focus without any window disappearing :)
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?
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.
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?
Re: activateWindow() doesn't work
Could you make a minimal compilable example-program demonstrating the problem and post it here?
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.