PDA

View Full Version : Commaseparated list with inline-completion with QLineEdit and QCompleter



petgru
17th July 2007, 11:50
Hello,

I'm currently developing a tagging-dialog for a media company using qt4 on their client software. The dialog has a QLineEdit where you is supposed to be able to enter a comma separated list of tags. A feature we have been looking to add to this is auto-completion of the tags.

This is the current code:


QCompleter *completer = new QCompleter(complist);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setCompletionMode(QCompleter::InlineCompletion);
ui.tagEdit->setCompleter(completer);
completer->setCompletionPrefix ( text.split(",").back().trimmed().toLower() );

It works ok for the first word, when you start writing on a empty line. But I also want it to work, as if it was a blank line, after a comma. ie. if you write "indie, roc" the last word should inline-complete to rock the sameway as if you only wrote "roc". Hope that make sens.

patrik08
17th July 2007, 12:35
I have build
http://www.qt-apps.org/content/show.php/QKeyWord+grep+Robot+-+Word-Completer?content=59422

word completer from DB sqlite and grep word from text....

to insert comma separated word... replace Space and special sign by ##_## as example
and after iterate QTextDocument to replace the placeholder....

completer not like space...

petgru
17th July 2007, 16:00
Solved it. Thx :) If you want to see the result, download the Last.fm client v1.4 when it's released.

chezifresh
21st December 2010, 01:35
Here's a stupid simple solution. I like this one the best
http://john.nachtimwald.com/2009/07/04/qcompleter-and-comma-separated-tags/

chezifresh
21st January 2011, 01:27
This also seems to do the job for the most part. When you actually do a completion it replaces the text in the line edit so more work might be needed or special handling on the line edit side would have to be implemented


class QdTermCompleter(QtGui.QCompleter):
def __init__(self, parent=None):
QtGui.QCompleter.__init__(self, [], parent)
self.terms = []

def setTerms(self, terms):
self.model().setStringList(terms)

def splitPath(self, path):
raw_values = str(path).split(",")
values = [val.strip() for val in raw_values if val.strip()]
if len(raw_values) != len(values):
return [path]
return [values[-1]]