Results 1 to 5 of 5

Thread: Commaseparated list with inline-completion with QLineEdit and QCompleter

  1. #1
    Join Date
    Jul 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Commaseparated list with inline-completion with QLineEdit and QCompleter

    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:
    Qt Code:
    1. QCompleter *completer = new QCompleter(complist);
    2. completer->setCaseSensitivity(Qt::CaseInsensitive);
    3. completer->setCompletionMode(QCompleter::InlineCompletion);
    4. ui.tagEdit->setCompleter(completer);
    5. completer->setCompletionPrefix ( text.split(",").back().trimmed().toLower() );
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Commaseparated list with inline-completion with QLineEdit and QCompleter

    I have build
    http://www.qt-apps.org/content/show....?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...

  3. #3
    Join Date
    Jul 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Commaseparated list with inline-completion with QLineEdit and QCompleter

    Solved it. Thx If you want to see the result, download the Last.fm client v1.4 when it's released.

  4. #4
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: Commaseparated list with inline-completion with QLineEdit and QCompleter

    Here's a stupid simple solution. I like this one the best
    http://john.nachtimwald.com/2009/07/...eparated-tags/

  5. #5
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: Commaseparated list with inline-completion with QLineEdit and QCompleter

    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

    Qt Code:
    1. class QdTermCompleter(QtGui.QCompleter):
    2. def __init__(self, parent=None):
    3. QtGui.QCompleter.__init__(self, [], parent)
    4. self.terms = []
    5.  
    6. def setTerms(self, terms):
    7. self.model().setStringList(terms)
    8.  
    9. def splitPath(self, path):
    10. raw_values = str(path).split(",")
    11. values = [val.strip() for val in raw_values if val.strip()]
    12. if len(raw_values) != len(values):
    13. return [path]
    14. return [values[-1]]
    To copy to clipboard, switch view to plain text mode 

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.