PDA

View Full Version : setFocus problem



roxton
11th February 2009, 12:07
I have two windows - the main and the tool window (an image viewer). The image viewer window is created with the flag Qt::Tool: window.setWindowFlags (Qt::Tool); (for some reasons).
Now I need to show this window and give the focus to it. When I simple call:


img_viewer->window.show();

...the focus returns to the main window. When I call the setFocus for the image viewer's window, nothing happens.
The image viewer's window has only one widget - QLabel. Maybe the window can be focused if only it has a focusable widget such as QLineEdit?

talk2amulya
11th February 2009, 13:19
try using setFocusPolicy. consult QT Assistant


focusPolicy : Qt::FocusPolicy
This property holds the way the widget accepts keyboard focus.
The policy is Qt::TabFocus if the widget accepts keyboard focus by tabbing, Qt::ClickFocus if the widget accepts focus by clicking, Qt::StrongFocus if it accepts both, and Qt::NoFocus (the default) if it does not accept focus at all.

You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widget's constructor. For instance, the QLineEdit constructor calls setFocusPolicy(Qt::StrongFocus).

Access functions:
Qt::FocusPolicy focusPolicy () const
void setFocusPolicy ( Qt::FocusPolicy policy )

roxton
11th February 2009, 23:16
Thank you, I'll try to play with it, but currently (with no in-deep testing) it doesn't help. As I can understand, the tool window can't be focused by the program (but focusing manually welll) if it has no focusable widgets.

talk2amulya
12th February 2009, 05:41
if i m right, i believe a widget doesnt get a focus when it has QT::NoFocus as its focus policy.. maybe u can look for that