Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. keyPressEvent not being driven
Forum Update on Monday, May 27th 2025

keyPressEvent not being driven

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 327 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    I'm clearly missing a crucial piece of setup for a custom QWidget.

    The ctor says:

    	setFocusPolicy(Qt::StrongFocus);		// Make sure we get key events.
    

    but the keyPressEvent mf() is never driven :(

    protected:
    	void keyPressEvent(QKeyEvent * event) override;
    

    What have I missed?

    Thanks
    David

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      Your custom widget must have the focus.

      1 Reply Last reply
      1
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        Well I clicked on it and that should have given it focus (shouldn't it)?

        D.

        1 Reply Last reply
        0
        • PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #4

          Can anyone clarify what I need to do to get those events

          Thanks
          David

          JonBJ 1 Reply Last reply
          0
          • PerdrixP Perdrix

            Can anyone clarify what I need to do to get those events

            Thanks
            David

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Perdrix
            I don't know, but you may not be getting any responses because nobody thinks there ought be any problem? Are you able to test just this in a totally standalone program, not with whatever you have in your current application?

            1 Reply Last reply
            0
            • PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on last edited by Perdrix
              #6

              @JonB I can make the source of the custom Widget available to play with if you wish - you'd just need to stick into a main window or dlg.

              let me know if you'd like me to do that and I'll stick a small zip file somewhere you can grab it from.

              D.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved