PDA

View Full Version : How to have multiple QCompleters in one QLineEdit



leinad
13th March 2020, 12:43
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.

d_stranz
13th March 2020, 15:15
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.

leinad
13th March 2020, 16:02
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?

d_stranz
13th March 2020, 16:48
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.

leinad
13th March 2020, 18:24
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?

d_stranz
13th March 2020, 22:07
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.

leinad
15th March 2020, 21:58
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.

d_stranz
16th March 2020, 00:17
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.