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. Limit total number of completions in QCompleter
Forum Updated to NodeBB v4.3 + New Features

Limit total number of completions in QCompleter

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

    How can I limit the number of completions in QCompleter, such as with this example https://doc.qt.io/qt-5/qtwidgets-tools-customcompleter-example.html , such that only a specific number of closest matches are shown (not just the ones visible without scrolling)?

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

      Hi,

      Isn't QCompleter's maxVisibleItems property what you are looking for ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Isn't QCompleter's maxVisibleItems property what you are looking for ?

        L Offline
        L Offline
        Lurkki
        wrote on last edited by
        #3

        @SGaist No, since that doesn't prevent more than that being shown on the item view altogether.

        JonBJ 1 Reply Last reply
        0
        • L Lurkki

          @SGaist No, since that doesn't prevent more than that being shown on the item view altogether.

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

          @Lurkki
          I did look at this yesterday, and did understand you were not talking about the visible items.

          I presume your use case is that you have lots of potential completions available, and it is "expensive" to calculate/return them all, so you want to restrict how many are returned.

          Not that I know exactly how to do this, but since I do not see any in-built support for this in QCompleter methods I assume you must do this yourself. In some shape or form, interpose a QAbstractProxyModel between the QCompleter and your actual data, so that it only returns to the completer the maximum number of items you desire. You may (well) find you need to act on user typing each search character, so that you can adjust the hits returned depending on what user has typed so far.

          L 1 Reply Last reply
          0
          • JonBJ JonB

            @Lurkki
            I did look at this yesterday, and did understand you were not talking about the visible items.

            I presume your use case is that you have lots of potential completions available, and it is "expensive" to calculate/return them all, so you want to restrict how many are returned.

            Not that I know exactly how to do this, but since I do not see any in-built support for this in QCompleter methods I assume you must do this yourself. In some shape or form, interpose a QAbstractProxyModel between the QCompleter and your actual data, so that it only returns to the completer the maximum number of items you desire. You may (well) find you need to act on user typing each search character, so that you can adjust the hits returned depending on what user has typed so far.

            L Offline
            L Offline
            Lurkki
            wrote on last edited by
            #5

            @JonB Yes. The best method I've found so far is to take the completion model, and when the completable text updates, create a copy of the completionModel and limit the rowCount in that model. It's quite inefficient though since a copy could probably be prevented in some other way.

            JonBJ 1 Reply Last reply
            0
            • L Lurkki

              @JonB Yes. The best method I've found so far is to take the completion model, and when the completable text updates, create a copy of the completionModel and limit the rowCount in that model. It's quite inefficient though since a copy could probably be prevented in some other way.

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

              @Lurkki said in Limit total number of completions in QCompleter:

              create a copy of the completionModel

              I admit I haven't looked at how it can be coded, but wouldn't a proxy model (with a limited rowCount() return) obviate any copying of the model data?

              L 1 Reply Last reply
              0
              • JonBJ JonB

                @Lurkki said in Limit total number of completions in QCompleter:

                create a copy of the completionModel

                I admit I haven't looked at how it can be coded, but wouldn't a proxy model (with a limited rowCount() return) obviate any copying of the model data?

                L Offline
                L Offline
                Lurkki
                wrote on last edited by
                #7

                @JonB Creating a proxy model from the QCompleter's completionModel doesn't work, since the QCompleter destroys the model the proxy model is trying to use, and you get a segfault.

                1 Reply Last reply
                1
                • L Offline
                  L Offline
                  Lurkki
                  wrote on last edited by Lurkki
                  #8

                  I ended up creating a QSortFilterProxyModel derived class with a limited row count and set that as the model for QCompleter and do the searching/filtering with that model instead of QCompleter, so the relationship goes as follows:

                  Original model <-> Proxy model -> QCompleter
                                          ^
                                          |
                                       QTextEdit
                  
                  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