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. Spell checking for QLineEdit – Is it possible?
Qt 6.11 is out! See what's new in the release blog

Spell checking for QLineEdit – Is it possible?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.1k Views 2 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
    PtSl
    wrote on last edited by PtSl
    #1

    Hi,

    is there a way to add spell checking to QLineEdit?

    I know that QTextEdit can be made to look like a single-line input by setting its height to around 25 pixels and intercepting keyPressEvent to block Qt.Key_Enter and Qt.Key_Return. But honestly, that feels like a bit of a hack.

    Is there are more straightforward solution?
    Any suggestions are appreciated!

    Peter

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • P Offline
      P Offline
      PtSl
      wrote on last edited by PtSl
      #2

      This is the desired outcome with a modified QTextEdit. Can there be a more systematic solution?

      QTextEdit.png

      1 Reply Last reply
      0
      • P PtSl

        Hi,

        is there a way to add spell checking to QLineEdit?

        I know that QTextEdit can be made to look like a single-line input by setting its height to around 25 pixels and intercepting keyPressEvent to block Qt.Key_Enter and Qt.Key_Return. But honestly, that feels like a bit of a hack.

        Is there are more straightforward solution?
        Any suggestions are appreciated!

        Peter

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

        @PtSl
        As per Googling QLineEdit spell check there is nothing supplied. Other people seem to have added this, e.g. https://blog.ssokolow.com/archives/2022/07/22/a-qlineedit-replacement-with-spell-checking/ but apparently by putting it on a QPlainTextEdit and then making that look like a single line QLineEdit. Which seems to be about where you are at. If there were a "more straightforward solution" for a QLineEdit I would expect to have found it. If you are going to write your own code to intercept key presses on a QText[Plain]Edit and deal with spellchecking I can't see why you couldn't do that on a QLineEdit if that is what you want to stick to, but have not looked into it.

        P.S.
        Now that you have posted what you would like, I'm not at sure you would get "red squiggly underlines" in QLineEdit. QTextEdit at least supports HTML, but I don't think QLineEdit does. So one would assume that at least would require intercepting paint() to achieve the visuals, apart from the character-typing-intercepting and spell-check itself.

        1 Reply Last reply
        0
        • P PtSl

          Hi,

          is there a way to add spell checking to QLineEdit?

          I know that QTextEdit can be made to look like a single-line input by setting its height to around 25 pixels and intercepting keyPressEvent to block Qt.Key_Enter and Qt.Key_Return. But honestly, that feels like a bit of a hack.

          Is there are more straightforward solution?
          Any suggestions are appreciated!

          Peter

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @PtSl

          Hi,

          it's built for Qt5 but you could try

          • https://github.com/manisandro/qtspell

          and read through a related topic here

          Maybe a QValidator with a dictionary linked to it also helps


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          JonBJ 1 Reply Last reply
          0
          • P Offline
            P Offline
            PtSl
            wrote on last edited by
            #5

            Intercepting the key presses is meant to prevent multi-line text. I want to avoid this:

            Multi-line text.png

            1 Reply Last reply
            0
            • Pl45m4P Pl45m4

              @PtSl

              Hi,

              it's built for Qt5 but you could try

              • https://github.com/manisandro/qtspell

              and read through a related topic here

              Maybe a QValidator with a dictionary linked to it also helps

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

              @Pl45m4 said in Spell checking for QLineEdit – Is it possible?:

              https://github.com/manisandro/qtspell

              Yes, but this too says

              To check spelling in a QTextEdit or QPlainTextEdit, proceed as follows:

              I have not looked, but has it been written to allow for a QLineEdit? Or are we accepting that OP must change to Q[Plain]TextEdit?

              and read through a related topic here

              I had seen that but it didn't get very far.... And it's MacOS only.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                PtSl
                wrote on last edited by
                #7

                Thank you, guys, for your responses and the references you provided! I appreciate that there are some ready solutions. I will check them out to adapt them to my case.

                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