Results 1 to 7 of 7

Thread: qtableview qcompleter

  1. #1
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default qtableview qcompleter

    Hi,
    I'm trying to get a tableview scroll to the current index I get from completer->currentIndex but I'm having no luck

    Qt Code:
    1. PlaceDialog::PlaceDialog(QWidget *parent, QString def, QString filename)
    2. {
    3. // etc
    4. completer = new QCompleter(this);
    5. completer->setCompletionMode( QCompleter::InlineCompletion);
    6. completer->setCaseSensitivity(Qt::CaseInsensitive);
    7. completer->setModel(model);
    8. edit = new LineEdit(this);
    9. connect(edit, SIGNAL(textChanged(QString)), this, SLOT(edited(QString)));
    10. edit->setCompleter(completer);
    11. //etc
    12. }
    13.  
    14. void PlaceDialog::edited(QString s)
    15. {
    16. QDebug()<s << completer->currentCompletion() << completer->currentIndex();
    17. table->setCurrentIndex(completer->currentIndex());
    18. }
    To copy to clipboard, switch view to plain text mode 

    I can see the completer working, the lineedit is filled with the completing but the index stays at 0.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qtableview qcompleter

    QAbstractItemView::setCurrentIndex() just sets the cell for the given index to be the current one, e.g. receiving keyboard events, usually also becoming selected.

    For your initial decscription you want to scroll to that cell, see QAbstractItemView::scrollTo()

    Cheers,
    _

  3. #3
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: qtableview qcompleter

    Thanks, I tried that, no change.
    I think my problem is something else because in the textChanged slot completer->currentCompletion() always returns the correct string BUT completer->currentRow() and completer->currentIndex() somehow always return 0.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qtableview qcompleter

    Well, textChanged() is emitted whenever the line edit's text changes.
    Have you tried listening to the completer's signals?

    Cheers,
    _

  5. #5
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: qtableview qcompleter

    Do you have an example of what you mean? QCompleter only has signals for when an item in the popup list is activated or higlighted. With Completer::InlineCompletion there is no popup

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qtableview qcompleter

    Ah, sorry, missed the inline completion bit.

    I assume currentCompletion() is also never anything other than a null QString?

    Hmm.
    You could try calling QAbstractItemModel::match() and call scrollTo() if the result has only one entry, i.e. when the match is unique.

    Cheers,
    _

  7. #7
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: qtableview qcompleter

    Yes I had been trying something like that. Fortunately currentCompletion() returns the correct string else I wouldn't have a clue at all. This works:
    Qt Code:
    1. void PlaceDialog::edited(QString s)
    2. {
    3. QModelIndexList matches = model->match(model->index(0, 0), Qt::DisplayRole, completer->currentCompletion());
    4. foreach(const QModelIndex &index, matches)
    5. {
    6. table->setCurrentIndex(model->index(index.row(), 0));
    7. break;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QCompleter + SQL
    By Wild Pointer in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2012, 11:18
  2. Qcompleter
    By wambagilles in forum Qt Programming
    Replies: 7
    Last Post: 6th April 2011, 09:14
  3. QCompleter Help
    By shinegun in forum Qt Programming
    Replies: 0
    Last Post: 2nd September 2010, 14:26
  4. QTextEdit and QCompleter
    By nivel in forum Qt Programming
    Replies: 2
    Last Post: 14th June 2009, 04:18
  5. Replies: 1
    Last Post: 12th October 2008, 09:21

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.