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]Get QModelindex
Forum Updated to NodeBB v4.3 + New Features

[Solved]Get QModelindex

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 6.6k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    toho71
    wrote on last edited by
    #1

    I got a treeview and a QFileSystemModel.
    Yes it,s a simpel file explorer.

    And I want to show all data about the file like size type etc.etc

    But I also want to show the file and its data in another Textbrowser so when I click on the filename in the Treeview its OK but when I click on other columns in the same row it's not possible to show the file.

    I want to show the file also if I clic on the second column or third or etc etc.
    Here is the code to get the file.

    @void Info::on_fileListTree_doubleClicked(QModelIndex index)
    {
    openfile(filemodel->fileName(index));
    }
    @

    I know that I need to change the index to the first column in the row but how?

    And another question.

    How could i get the same event as if i Click on the Row when I change row with the arrows on my keyboard.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      First of all, I think you should at least make sure that you have the right selection mode enabled. You should use row-type selection.

      Then, if you want to respond to a (double) click on a cell in a column other than column 0 as if it were in column 0, you could do something like this:

      @
      //untested code
      void Info::on_fileListTree_doubleClicked(QModelIndex index)
      {
      if (index.column() > 0) {
      //get index for column 0 in the same row
      index = index.model().index(index.row(), 0, index.parent());
      }
      openfile(filemodel->fileName(index));
      }
      @

      1 Reply Last reply
      0
      • T Offline
        T Offline
        toho71
        wrote on last edited by
        #3

        Yes that's exctly what I wanted and I got the selection mode sat to rowselect.

        Thanks

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          By the way, I think the code becomes easier to read if you rename the index variable to something else. For times index in one line of code is a bit confusing, perhaps ;-)

          1 Reply Last reply
          0
          • T Offline
            T Offline
            toho71
            wrote on last edited by
            #5

            Thanks.
            Do you have an answer to my other question also.

            bq. How could i get the same event as if i Click on the Row when I change row with the arrows on my keyboard.

            I miss the selection/row change or something in the slots

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Did you try to connect to the itemActivated() signal?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                toho71
                wrote on last edited by
                #7

                Nope didn't find it in the treeview doc:

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  Get the [[Doc:QItemSelectionModel]] with selectionModel(), then connect to one or more of the signals currentChanged, selectionChanged or currentRowChanged.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    toho71
                    wrote on last edited by
                    #9

                    Ok thanks I try this a little later.

                    1 Reply Last reply
                    0

                    • Login

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