Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Stop propagating key event
Qt 6.11 is out! See what's new in the release blog

Stop propagating key event

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 6.6k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Milnadar
    wrote on last edited by
    #1

    Hi all;
    Is there an ability to stop propagating key event to parent item?
    By calling event.accepted = true, the default action is no longer working;
    For example, i have textEdit element, and when clicking the arrow_up button, cursor moves to the previous line of the text if exists, and if not exists parent item receives event;
    Is it possible to leave default action on press and stop propagating event?
    Thanks.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dmcr
      wrote on last edited by
      #2

      If i have understood correctly your question, on way is to intercept the event directly. For ex in your button, you put some onMouseClicked : {}, but then inside you have to put the code to make the cursor go upper if necessary.
      Normally in that case the parent wont have any event propagated.

      dmcr

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        You can do such things by subclassing the widget. For a QTextEdit e.g.:

        @
        void MyTextEdit::keyPressEvent ( QKeyEvent * event )
        {
        QTextEdit::keyPressEvent(event); // do default actions
        event->setAccepted(true); // prevent processing in the parent
        }
        @

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dmcr
          wrote on last edited by
          #4

          As we are in a QML section, my response was a QML one, perhaps without any connection with the question, i agree, but may i suggest to change the section ?

          dmcr

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            Ups, sorry, I haven't looked at the sub forum :-(
            But perhaps qml has similar things?

            You have a perent element and add an event handler there which is empry or sets accepted to true.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            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