PDA

View Full Version : activateWindow() doesn't work



roxton
25th December 2008, 16:17
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:



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.

drhex
25th December 2008, 16:22
What if you also call QWidget::setFocus() on a widget in your main window?

spirit
25th December 2008, 16:24
try to do like this


...
raise();
activateWindow();
...

roxton
25th December 2008, 16:50
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:


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 :)

drhex
25th December 2008, 18:36
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?

roxton
25th December 2008, 21:15
Yes, I'm on Linux, Qt 4.4.3. Desktop effect are turned off. Soon I'll test this focusing problem on Windows XP.

roxton
25th December 2008, 23:06
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?

drhex
26th December 2008, 09:46
Could you make a minimal compilable example-program demonstrating the problem and post it here?

roxton
26th December 2008, 09:49
I'll post an example a bit later. Currently I've solved the problem calling setWindowFlags (Qt::Tool) for the secondary window.