Results 1 to 8 of 8

Thread: How to have multiple QCompleters in one QLineEdit

  1. #1
    Join Date
    Dec 2019
    Posts
    13
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default How to have multiple QCompleters in one QLineEdit

    Hi,

    I checked the web and could not find an answer to this issue I'm trying to solve. Perhaps someone can help me.
    I'd like to have several QCompleters in the same QLineEdit and allow users to select an element in each completer independent of the others:

    QCompleter1 QCompleter2 QCompleter3 ….

    Users can go and select an element in QCompleter2 without affecting the other two.
    Would anyone know how to do this?

    Thanks and appreciate your help.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,491
    Thanks
    252
    Thanked 717 Times in 707 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to have multiple QCompleters in one QLineEdit

    allow users to select an element in each completer independent of the others
    I am not clear on what you are trying to accomplish. If the user types "abc" and you have three completers where the first one has "abcd" and "abce", the second one has "abcf" and "abcg", etc., what will you display to the user? If you don't want to confuse the user, it should probably look exactly the same as if only a single completer with all of the possibilities was displayed.

    The difference might be that the results are not sorted (except within each group). This could be pretty annoying actually, since the user would have to scan all three lists for the right completion because to them it would look like a partially sorted list and they would be afraid of missing something.

    Users can go and select an element in QCompleter2 without affecting the other two.
    Would anyone know how to do this?
    I think the key to doing this is not to use multiple QCompleter instances, but to use multiple models that are all controlled by a single model that the QCompleter uses. The completer asks the controlling model for completions, and the controlling model asks each of the models under it for their list of completions. It could combine these, sort them, and pass them up to the completer for display to the user as a single sorted list. Underneath, the controller model would have to keep track of which completion came from which sub-model.

    This might be tricky to implement, but it would give you a pretty powerful way to implement a context-sensitive completer, where you could plug in the right set of completion models based on what the user is doing at that time.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Dec 2019
    Posts
    13
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to have multiple QCompleters in one QLineEdit

    I need separate completer's because each entry is un-related to the other. If I use one completer with multiple models the sorting and arranging becomes very complicated. Essentially I'm doing database queries where each completer provides different parameters. If I combine the models, the query will have so many combinations it will be impossible for the user to understand. Think of it as having multiple comb-boxes and each combo-box has a different selection. After all the selections are made, I concatenate the results from each combo-box and do the query. The user can now just modify the query by changing a single comb-box selection. I want to do the same thing just have a lineEdit with multiple completer's. Kind of multiple combo-boxes in a single lineEdit. Is this possible to have multiple completer's in a lineEdit?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,491
    Thanks
    252
    Thanked 717 Times in 707 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to have multiple QCompleters in one QLineEdit

    Kind of multiple combo-boxes in a single lineEdit. Is this possible to have multiple completer's in a lineEdit?
    No, not in the standard QLineEdit. If you want three completers, then you need three line edits, each with its own completer. Concatenate the three strings from each line edit to form your query.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Dec 2019
    Posts
    13
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to have multiple QCompleters in one QLineEdit

    So if I want them on one line, I need to overlay the linedits? How would that be different than just using a bunch of combo-boxes placed next to each other?

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,491
    Thanks
    252
    Thanked 717 Times in 707 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to have multiple QCompleters in one QLineEdit

    How would that be different than just using a bunch of combo-boxes placed next to each other?
    It would not be any different.

    I need to overlay the linedits?
    No. Think about how that would look. If they were overlaid, what would you do? Make the first one visible, have the user complete the text for that, then hide it and make the second one visible, and so on? The user could never see the complete query, only the last part they chose. And think about the interaction. What if the user is editing the second part and realizes he made a mistake on the first choice. How do you go back if it is now hidden? It's the kind of thing that would have me screaming at my PC.

    So yes, I would put the line edits side by side and put a different completer in each.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Dec 2019
    Posts
    13
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to have multiple QCompleters in one QLineEdit

    Thanks but it seems to me its much better if I just have multiple combo-boxes and completer's which actually looks a little nicer.

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,491
    Thanks
    252
    Thanked 717 Times in 707 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to have multiple QCompleters in one QLineEdit

    It seems to me that we are talking about the same thing but using different words. Whether you use line edits or comboboxes, it's the same idea - if you have a three-part phrase and have different ways to complete each part, then you need three widgets and three completers, plus a way to validate that the query you construct from the three inputs makes sense.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 23rd July 2019, 18:24
  2. QLineEdit with multiple strings by default.
    By robgeek in forum Newbie
    Replies: 1
    Last Post: 24th June 2019, 06:30
  3. Replies: 2
    Last Post: 9th July 2016, 10:59
  4. Replies: 1
    Last Post: 12th October 2010, 22:20
  5. QLineedit Multiple Validation
    By csvivek in forum Qt Programming
    Replies: 13
    Last Post: 4th May 2008, 20:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.