Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Find correct index to set selection programmatically

[solved] Find correct index to set selection programmatically

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bmahf
    wrote on 11 Dec 2014, 20:45 last edited by
    #1

    I have a QListView and the model is a QFileSystemModel. The view only shows the files in the directory that is currently set as the root directory. If a particular known file name exists in the view list, I need to set that item as selected. I therefore need to run through the file names in the view, or in the QFileSystemModel, in order to get the index for that item to select it. Problem is that I haven't yet found a way of iterating to find the correct index for setting the selection. I have tried a number of different approaches, such as querying the view's model (view->model()) and asking it for the number of children and the row count, but row count is 1 and number of children is 0, while the number of files I see when the view is populated is 6. I also tried
    @
    QString child = (QString)view->childAt(0,0)
    @
    since I know what I'm expecting from the first row, but the string was empty. When I print the root.data() using qDebug(), I get "QVariant(QString, "Root")", which is the name of the directory that contains all the files shown in the view. Does someone have an idea as to how you would go about doing this?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Dec 2014, 23:50 last edited by
      #2

      Hi,

      Isn't "QFileSystemModel::index":http://doc.qt.io/qt-5/qfilesystemmodel.html#index-2 what you want ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bmahf
        wrote on 12 Dec 2014, 00:07 last edited by
        #3

        Wow, that was an oversight. I thought I'd scoured the documentation, but I totally overlooked that. Thanks.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Dec 2014, 00:44 last edited by
          #4

          You're welcome !

          If that answers your question, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          11 Dec 2014, 20:45

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved