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 current file path QTreeView
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Get current file path QTreeView

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 4.0k 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.
  • L Offline
    L Offline
    leandrogs
    wrote on last edited by
    #1

    Hello guys. I have to create a function to remove files and folders/subfolders when the user do a right click in an item on the QTreeView. I know that i can use this method QFileInfo QDirModel::fileInfo ( const QModelIndex & index ) const but i only have a QPoint received from customContextMenuRequested(const QPoint&) signal.

    Any ideas on how i can do that? How i can get the file path using a QPoint?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You could use QTreeView::indexAt to get the index from the point and then continue the same way you already do

      Hope it helps

      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
      • L Offline
        L Offline
        leandrogs
        wrote on last edited by
        #3

        @ShowContextMenu(const QPoint& pos)
        {
        QDirModel dir;
        qDebug() << dir.filePath(this->ui->treeView->indexAt(pos));
        }@

        It will return an empty string. Why? :(

        If i call @qDebug() << this->ui->treeView->indexAt(pos).data();@ returns the correct item data.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The index returned by treeView->indexAt() doesn't belong to the QDirModel you just created, it belongs to the model you set on the QTreeView. Use that model and you should be fine

          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
          • L Offline
            L Offline
            leandrogs
            wrote on last edited by
            #5

            I need more info. How do i do that?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              If you have a QTreeView, you have created a model (probably a QFileSystemModel or a QDirModel) somewhere and called treeView->setModel(model), it's that model you have to use

              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
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                You can also get the model from treeView:

                @QXXXModel *model = qobject_cast<QXXXModel *>(treeView->mode());@

                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
                • L Offline
                  L Offline
                  leandrogs
                  wrote on last edited by
                  #8

                  Works fine now. Thank you :D

                  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