Results 1 to 2 of 2

Thread: get current item from QCompleter

  1. #1
    Join Date
    Mar 2006
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 3 Posts

    Question get current item from QCompleter

    i have QCompleter and when i start completion i need to get current(first) item from popup list.

    some code :
    Qt Code:
    1. //CompleterModel == QStandardItemModel
    2. //mComplet is QCompleter
    3. //
    4. showCompleter();
    5. if (mComplet->popup()->isVisible())
    6. {
    7. QModelIndex index = mComplet->popup()->currentIndex();
    8. if (index.isValid())
    9. {
    10. CompleterModel* model = (CompleterModel*)mComplet->model();
    11. if (model)
    12. {
    13. QStandardItem* item = model->itemFromIndex(index);
    14. if (item)
    15. cout <<"item OK"<<endl;
    16. else
    17. cout <<"item Error"<<endl;
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    so this function return "item Error" -- what's wrong?? (i think problem from completer sorting, but how to get proxy model?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: get current item from QCompleter

    Yes, the problem must be that view returns an index of the proxy model, indeed. Perhaps you could try a hackish way of using mComplet->findChild<QAbstractProxyModel*>() and then QAbstractProxyModel::mapToSource().
    J-P Nurmi

Similar Threads

  1. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  2. Replies: 15
    Last Post: 21st April 2007, 17:46
  3. Replies: 1
    Last Post: 19th April 2007, 22:23
  4. Comparing Items In List Box
    By kenny_isles in forum Qt Programming
    Replies: 9
    Last Post: 21st February 2007, 13:06
  5. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 01:34

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.