Results 1 to 4 of 4

Thread: setFocus problem

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

    Default setFocus problem

    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:
    Qt Code:
    1. img_viewer->window.show();
    To copy to clipboard, switch view to plain text mode 
    ...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?

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setFocus problem

    try using setFocusPolicy. consult QT Assistant

    Qt Code:
    1. focusPolicy : Qt::FocusPolicy
    2. This property holds the way the widget accepts keyboard focus.
    3. 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.
    4.  
    5. 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).
    6.  
    7. Access functions:
    8. Qt::FocusPolicy focusPolicy () const
    9. void setFocusPolicy ( Qt::FocusPolicy policy )
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: setFocus problem

    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.

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setFocus problem

    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

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 13:05
  2. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 15:38
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.