Results 1 to 3 of 3

Thread: Question about focus

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

    Default Question about focus

    Hi,
    I have a doubt regarding focus. Maybe this is not a Qt related topic, if so sorry in advance.
    I have a Widget inherited from QWidget having some children ( push buttons and other widgets ).
    So:

    Qt Code:
    1. class WaveWidget : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. WaveWidget( QWidget* parent = 0 );
    7. virtual ~WaveWidget();
    8.  
    9. void setSoundFile( QString soundName_ );
    10. void closeSoundFile( QString soundName_ );
    11.  
    12. public slots:
    13. void playSound();
    14. void stopSound();
    15. void zoomIn();
    16. void zoomOut();
    17. void setZoomFactor( float f );
    18.  
    19. signals:
    20. void zoomFactorChanged( float );
    21.  
    22. protected:
    23. virtual void focusInEvent( QFocusEvent * );
    24. virtual void focusOutEvent( QFocusEvent * );
    25. virtual void keyPressEvent( QKeyEvent* event );
    26.  
    27. private:
    28. WaveDisplay* m_WaveDisplay;
    29. PanelInfo* m_panel;
    30.  
    31. SoundData* m_wave;
    32.  
    33. QPushButton* button1;
    34. QPushButton* button2;
    35. QPushButton* button3;
    36. QPushButton* button4;
    37. QPushButton* button5;
    38. QPushButton* button6;
    39. QPushButton* button7;
    40. QPushButton* button8;
    41. QPushButton* button9;
    42. QPushButton* button10;
    43. QPushButton* m_zoomInBtn;
    44. QPushButton* m_zoomOutBtn;
    45.  
    46. QLabel* m_titleLabel;
    47.  
    48. QLed* m_statusLed;
    49.  
    50. float m_ZoomFactor;
    51. };
    To copy to clipboard, switch view to plain text mode 

    The WaveWidget should react to keyboard keys pressed ( I reimplemented keyPressEvent ).
    If initially WaveWidget has focus, pressing tab the focus pass to it's children. In this case WaveWidges still react to keyboard keypressed?
    I would like yes, but I don't know how to implement such behaviour.

    Best Regards
    Franco Amato

  2. #2
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Question about focus

    You can install an event handler to catch the key events of the child widgets of your WaveWidget. This is what comes first on my mind. There might be an easier solution though...
    void QObject::installEventFilter ( QObject * filterObj )
    You will find more in the documentation.

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

    Default Re: Question about focus

    Quote Originally Posted by psih128 View Post
    You can install an event handler to catch the key events of the child widgets of your WaveWidget. This is what comes first on my mind. There might be an easier solution though...

    You will find more in the documentation.
    Hi thank you very much for your mail.
    I try to explain what I would implement ( hoping my poor english help me ).
    In my mainapplication I have a centralwidget cw.
    cw contains 2 wavewidget widgets ww
    so:
    cw
    |____ww1
    |____ww2

    every ww contains many widgets ( buttons and other.. see class WaveWidget description above - previous post - )

    I would implement this behaviour:
    User with tab ( or another key ) switch focus between ww1 and ww2 whitout passing for all children of every ww.
    For example focus is in ww1 -> user click tab -> focus on ww2 -> user click tab -> focus on ww1 -> so on...

    Is possible? I have no idea on how implement it.

    Best Regards,
    Franco
    Franco Amato

Similar Threads

  1. widget focus question
    By eva2002 in forum Newbie
    Replies: 1
    Last Post: 12th January 2010, 00:04
  2. Window focus question
    By waynew in forum Newbie
    Replies: 3
    Last Post: 31st October 2009, 23:11
  3. 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
  4. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09
  5. Focus Help please
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 15th November 2006, 18:09

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.