Results 1 to 6 of 6

Thread: How to signal when a Qwidget receive focus

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

    Default How to signal when a Qwidget receive focus

    Hi,
    I would signal to a QLed when a QWidget receive focus to accept keyboard input.
    Something as:

    Qt Code:
    1. connect( MyWidget, SIGNAL( focusReceived(bool) ),MyQLed, SLOT(setValue(bool)) );
    To copy to clipboard, switch view to plain text mode 

    but seems that QWidets class doesn't have such signal.
    How can I do?

    Best
    Franco Amato

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to signal when a Qwidget receive focus

    either subclass QWidget and reimplement focusInEvent and focusOutEvent to emit your custom signal or maybe simpler solution would be to install event filter on MyWidget and on focus events notify MyQLed about it.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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

    Default Re: How to signal when a Qwidget receive focus

    Quote Originally Posted by faldżip View Post
    either subclass QWidget and reimplement focusInEvent and focusOutEvent to emit your custom signal or maybe simpler solution would be to install event filter on MyWidget and on focus events notify MyQLed about it.
    Dear faldzip, how can I install the event filter you mentioned?
    Can you help me with a little example?
    Franco Amato

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to signal when a Qwidget receive focus

    There is a good example in Qt Docs: see QObject::eventFilter() and QObject::installEventFilter()
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #5
    Join Date
    Oct 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Android

    Default Re: How to signal when a Qwidget receive focus

    Qt Code:
    1. classA::classA(){
    2. ...
    3. ...
    4.  
    5. ui->lineEdit->installEventFilter(this);
    6.  
    7. }
    8.  
    9. bool classA::eventFilter(QObject *object, QEvent *event)
    10. {
    11. if(event->type() == event->FocusIn && object == ui->lineEdit)
    12. {
    13. //do something
    14. return true;
    15. }
    16. else
    17. {
    18. return false;
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to signal when a Qwidget receive focus

    Are you getting some kind of thrill by replying to 5 and 6 year old dead posts? You aren't adding anything useful by duplicating what has already been said by previous posters. You have done nothing more than to essentially copy and paste the code that was linked to in faldzip's last post.

    Read the forum, learn new things from it, but don't resurrect old posts if you have nothing new to add. Look at the date on the post before you reply to it. If the last reply was 6 years ago, let it rest in peace.

Similar Threads

  1. Replies: 3
    Last Post: 26th August 2009, 06:44
  2. Replies: 6
    Last Post: 3rd September 2008, 14:27
  3. Focus on a QWidget item in a QWidget
    By vycke in forum Qt Programming
    Replies: 10
    Last Post: 7th January 2008, 21:00
  4. Replies: 0
    Last Post: 23rd September 2007, 11:54
  5. Replies: 3
    Last Post: 8th September 2006, 18:54

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.