Results 1 to 3 of 3

Thread: keyPressEvent public or should it be protected

  1. #1
    Join Date
    Jun 2011
    Posts
    23
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default keyPressEvent public or should it be protected

    Hi,

    Is there any issues with making the slot keyPressEvent() public?

    I have a QWidget (called say A) that has a button on it which opens a QWidget window (called B) which gains the focus and I want certain keys entered on the keyboard to be ignored by 'B' and passed through to 'A' to be able to use. The only way I can get this to work is the move the header definition of keyPressEvent() from protected to public... is this a bad thing to do or is there a better way around it...

    Qt Code:
    1. void B::keyPressEvent(QKeyEvent *k)
    2. {
    3. if((B->hasFocus()) && !(k->key() >= Qt::Key_F1 && k->key() <= Qt::Key_F20))
    4. {
    5. QApplication::sendEvent(B->focusWidget(), k);
    6. }
    7. else
    8. {
    9. A->keyPressEvent(k); //This doesn't work if it is protected slot in A.h needs to be public slot
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Thank you for any help.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: keyPressEvent public or should it be protected

    Hi, you could send the event through the event system using QCoreApplication:ostEvent() or QCoreApplication::sendEvent(). That way the keyPressEvent() can stay protected.

    Ginsengelf

  3. #3
    Join Date
    Jun 2011
    Posts
    23
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: keyPressEvent public or should it be protected

    Thank you sendEvent worked

Similar Threads

  1. Replies: 3
    Last Post: 11th February 2018, 18:00
  2. Play WMA DRM (protected wma files)
    By walidos in forum Qt Programming
    Replies: 1
    Last Post: 11th February 2012, 18:01
  3. protected QGraphicsObject
    By stefan in forum Qt Programming
    Replies: 6
    Last Post: 19th August 2011, 17:04
  4. Virtual protected and private var
    By maddog_fr in forum Qt Programming
    Replies: 4
    Last Post: 19th November 2010, 16:14
  5. About Password Protected Files:
    By vermarajeev in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2007, 14:46

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.