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. QLineEdit how to detect every keypress?
Forum Updated to NodeBB v4.3 + New Features

QLineEdit how to detect every keypress?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.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.
  • P Offline
    P Offline
    Publicnamer
    wrote on last edited by
    #1

    I noticed there is no signal from QLineEdit for detecting single-character changes to the text field.
    How can this be done?
    I tried overrriding keyPressEvent(QKeyEvent *event) but that only gets called when I press Return.

    eyllanescE 1 Reply Last reply
    0
    • P Publicnamer

      I noticed there is no signal from QLineEdit for detecting single-character changes to the text field.
      How can this be done?
      I tried overrriding keyPressEvent(QKeyEvent *event) but that only gets called when I press Return.

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @Publicnamer keyPressEvent is the proper solution so I assume you have implemented it incorrectly, could you please show a compilable example of your intent?

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      P 1 Reply Last reply
      0
      • eyllanescE eyllanesc

        @Publicnamer keyPressEvent is the proper solution so I assume you have implemented it incorrectly, could you please show a compilable example of your intent?

        P Offline
        P Offline
        Publicnamer
        wrote on last edited by Publicnamer
        #3

        @eyllanesc I didn't subclass QLineEdit, that's why it didn't work.

        It doesn't matter though. Listening to cursorPositionChanged suffices. However I do think QLineEdit should be revised to allow for watching individual character changes without subclassing. Other GUIs allow that.

        jeremy_kJ eyllanescE 2 Replies Last reply
        0
        • P Publicnamer

          @eyllanesc I didn't subclass QLineEdit, that's why it didn't work.

          It doesn't matter though. Listening to cursorPositionChanged suffices. However I do think QLineEdit should be revised to allow for watching individual character changes without subclassing. Other GUIs allow that.

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #4

          Does single-character change refer to inserting and deleting text, or something else?

          Asking a question about code? http://eel.is/iso-c++/testcase/

          P 1 Reply Last reply
          0
          • P Publicnamer

            @eyllanesc I didn't subclass QLineEdit, that's why it didn't work.

            It doesn't matter though. Listening to cursorPositionChanged suffices. However I do think QLineEdit should be revised to allow for watching individual character changes without subclassing. Other GUIs allow that.

            eyllanescE Offline
            eyllanescE Offline
            eyllanesc
            wrote on last edited by eyllanesc
            #5

            @Publicnamer It should be noted that cursorPositionChanged not only fires when you type a letter, for example it is emitted when you move the cursor by clicking with the mouse.

            If you don't want to subclass QLineEdit then you can listen to keyboard events through an eventfilter. If you just want to hear some special keys then you can use QShortcuts.

            The logic of a QWidget is to balance the number of behaviors with the minimum expected. If you want more behaviors then that implies a cost in memory, in addition to that you would never be happy at all. So the Qt developers implement the behaviors that they consider necessary, if you want other behaviors then that's your job.

            If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

            1 Reply Last reply
            0
            • jeremy_kJ jeremy_k

              Does single-character change refer to inserting and deleting text, or something else?

              P Offline
              P Offline
              Publicnamer
              wrote on last edited by
              #6

              @jeremy_k All of the above.
              I'm looking for something like iOS's UITextViewDelegate's method textField:shouldChangeCharactersInRange:replacementString:
              https://developer.apple.com/documentation/uikit/uitextfielddelegate

              eyllanescE jeremy_kJ 2 Replies Last reply
              0
              • P Publicnamer

                @jeremy_k All of the above.
                I'm looking for something like iOS's UITextViewDelegate's method textField:shouldChangeCharactersInRange:replacementString:
                https://developer.apple.com/documentation/uikit/uitextfielddelegate

                eyllanescE Offline
                eyllanescE Offline
                eyllanesc
                wrote on last edited by
                #7

                @Publicnamer This component looks like QValidator: https://doc.qt.io/qt-5/qvalidator.html

                If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                1 Reply Last reply
                0
                • P Publicnamer

                  @jeremy_k All of the above.
                  I'm looking for something like iOS's UITextViewDelegate's method textField:shouldChangeCharactersInRange:replacementString:
                  https://developer.apple.com/documentation/uikit/uitextfielddelegate

                  jeremy_kJ Offline
                  jeremy_kJ Offline
                  jeremy_k
                  wrote on last edited by
                  #8

                  @Publicnamer said in QLineEdit how to detect every keypress?:

                  @jeremy_k All of the above.
                  I'm looking for something like iOS's UITextViewDelegate's method textField:shouldChangeCharactersInRange:replacementString:
                  https://developer.apple.com/documentation/uikit/uitextfielddelegate

                  All of the above in response to something else doesn't clarify anything. What does QLineEdit::textChanged() or QLineEdit::textEdited() miss?

                  Asking a question about code? http://eel.is/iso-c++/testcase/

                  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