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. text edit completer
Forum Updated to NodeBB v4.3 + New Features

text edit completer

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.3k 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i'm looking at this example as a reference for me to write a completer for QPlainTextEdit subclass:
    http://doc.qt.io/qt-5/qtwidgets-tools-customcompleter-example.html

    however, it only shows autocompletion on some shortcut press. what i wanna do is, it to behave like a normal auto completion, i.e. filter suggestion list based on what already typed.

    i can think of updating the model with every key press but i think that's a heavy operation. any better solution?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      That is the normal operation. (guess on type)

      QStringList wordList;
        wordList << "alpha" << "omega" << "omicron" << "zeta";
        QCompleter *completer = new QCompleter(wordList, this);
        completer->setCaseSensitivity(Qt::CaseInsensitive);
        ui->lineEdit->setCompleter(completer);
      

      Guess as soon as you write. However for a TextEdit that might be annoying and hence i thinks that's why sample uses shortcut.

      U 1 Reply Last reply
      3
      • mrjjM mrjj

        Hi
        That is the normal operation. (guess on type)

        QStringList wordList;
          wordList << "alpha" << "omega" << "omicron" << "zeta";
          QCompleter *completer = new QCompleter(wordList, this);
          completer->setCaseSensitivity(Qt::CaseInsensitive);
          ui->lineEdit->setCompleter(completer);
        

        Guess as soon as you write. However for a TextEdit that might be annoying and hence i thinks that's why sample uses shortcut.

        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @mrjj
        okay, but in my case i need it.

        mrjjM 1 Reply Last reply
        0
        • U user4592357

          @mrjj
          okay, but in my case i need it.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @user4592357
          hi
          You are free to call comple() at any moment. so its more up to you to trigger it.
          maybe on keypress will do it.

          U 1 Reply Last reply
          1
          • mrjjM mrjj

            @user4592357
            hi
            You are free to call comple() at any moment. so its more up to you to trigger it.
            maybe on keypress will do it.

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @mrjj
            i call it. i do it as in example. but in my case there are spaces in between the words, and i was selecting by text_cursor.select(QTextCursor::WordUnderCursor). changed that to text_cursor.select(QTextCursor::LineUnderCursor), now works!

            1 Reply Last reply
            2
            • U Offline
              U Offline
              user4592357
              wrote on last edited by user4592357
              #6

              there's also something else: as in the example, i applied setModelSorting(QCompleter::CaseSensitivelySortedModel) to the completer. however, it wasn't sorted, and i had to do completer->model()->sort(0) explicitly. i don't think i should've done that, right?

              i mean, just setModelSorting() should've done the job:
              from docs: This property holds the way the model is sorted

              mrjjM 1 Reply Last reply
              0
              • U user4592357

                there's also something else: as in the example, i applied setModelSorting(QCompleter::CaseSensitivelySortedModel) to the completer. however, it wasn't sorted, and i had to do completer->model()->sort(0) explicitly. i don't think i should've done that, right?

                i mean, just setModelSorting() should've done the job:
                from docs: This property holds the way the model is sorted

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @user4592357 said in text edit completer:

                setModelSorting

                Hi
                As far as i know its only for hinting the sort order. setting it wont
                tell model to sort. Its more like a clue for completer.

                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