Results 1 to 4 of 4

Thread: find item in QListView

  1. #1
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default find item in QListView

    I want to get the index of item of QListView and set at this item focus. The items are strings! How can I make it?

    I have made this is:
    Qt Code:
    1. void LicenceBuilder::findLeftSN(const QString& new_SN)
    2. {
    3. if(new_SN.isEmpty()) return;
    4.  
    5. model.setTable("DeviceList");
    6. model.select();
    7. QStringList listNames, selList;
    8. for(int i=0; i<model.rowCount(); ++i)
    9. {
    10. QSqlRecord record = model.record(i);
    11. listNames.append(record.value("serialNumber").toString());
    12. }
    13. foreach(QString name, listNames)
    14. if(name.indexOf(new_SN, 0, Qt::CaseInsensitive) != -1)
    15. selList.append(name);
    16.  
    17. /// What to do??????
    18. }
    To copy to clipboard, switch view to plain text mode 

    This slot must find index of item and set focus. Help me, please!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: find item in QListView

    have you had a look at QAbstractItemModel::match()?

  3. The following user says thank you to caduel for this useful post:

    AD (14th November 2008)

  4. #3
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: find item in QListView

    Thanks! I try

  5. #4
    Join Date
    Jun 2008
    Location
    Saint-Petersburg
    Posts
    50
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: find item in QListView

    GREAT THANKS! It helped me. This code resolve this problem:
    Qt Code:
    1. /// Поиск в левом списке номера, часть (или он весь) которого отражена в new_SN
    2. void LicenceBuilder::findLeftSN(const QString& new_SN)
    3. {
    4. // after phrase What to do??????
    5.  
    6. QModelIndexList indexList = model.match(model.index(0, 0), Qt::DisplayRole, selList.first());
    7. QModelIndex selectedIndex(indexList.first());
    8. listDBNumbers -> setCurrentIndex(selectedIndex);
    9. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to Modify QListView item height?
    By blackfox in forum Qt Programming
    Replies: 7
    Last Post: 16th May 2012, 11:38
  2. QListView item alignment
    By innerhippy in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2008, 09:32
  3. how to move item up and down in QListView
    By zhanglr in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2008, 14:39
  4. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  5. Replies: 17
    Last Post: 31st March 2006, 05:57

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.