Results 1 to 5 of 5

Thread: Switch the focus between 2 widgets

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Switch the focus between 2 widgets

    Quote Originally Posted by Lykurg View Post
    in wave_1 hold a pointer to wave_2 and vice versa. Then use QWidget::keyPressEvent() and there callwave_X->setFocus().

    Or use signal and slots instead of the pointers.
    Hi, I have a CentralWidget containing the 2 widget.
    I don't have to call setFocus from such container widget?

    I wrote this code

    Qt Code:
    1. void CentralWidget::keyPressEvent( QKeyEvent*pe )
    2. {
    3. switch( pe->key() )
    4. {
    5. case Qt::Key_Tab:
    6. {
    7. // switch the focus
    8. if( m_pWave2->hasFocus() )
    9. {
    10. m_pWave1->setFocus( Qt::TabFocusReason );
    11. }
    12. else if ( m_pWave1->hasFocus() )
    13. {
    14. m_pWave2->setFocus(Qt::TabFocusReason);
    15. }
    16.  
    17. break;
    18. }
    19.  
    20. default:
    21. QWidget::keyPressEvent(pe);
    22. break;
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    this can be ok?
    Last edited by franco.amato; 14th December 2009 at 21:39.
    Franco Amato

Similar Threads

  1. Window focus issues (How to force focus to a window?)
    By montylee in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2009, 01:00
  2. Replies: 0
    Last Post: 13th February 2009, 08:26
  3. Upper limit on number of widgets?
    By jdiewald in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2008, 23:00
  4. Force focus to a QTabWidget page's widget
    By thomaspu in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2008, 06:54
  5. Tab/Enter focus problem
    By b1 in forum Qt Programming
    Replies: 4
    Last Post: 23rd October 2006, 23:34

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.