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. Drag a QFileSystemModel item and drop it into Windows Desktop
Forum Updated to NodeBB v4.3 + New Features

Drag a QFileSystemModel item and drop it into Windows Desktop

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 1.8k 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #2

    You are trying to drag from the model to somewhere else or from somewhere else to the model?

    If the second is true you need to also reimplement the 2 methods:

    • http://doc.qt.io/Qt-5/qabstractitemmodel.html#canDropMimeData
    • http://doc.qt.io/Qt-5/qabstractitemmodel.html#dropMimeData

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    F 1 Reply Last reply
    0
    • VRoninV VRonin

      You are trying to drag from the model to somewhere else or from somewhere else to the model?

      If the second is true you need to also reimplement the 2 methods:

      • http://doc.qt.io/Qt-5/qabstractitemmodel.html#canDropMimeData
      • http://doc.qt.io/Qt-5/qabstractitemmodel.html#dropMimeData
      F Offline
      F Offline
      franc
      wrote on last edited by
      #3

      @VRonin from the model to somewhere else

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #4

        Then it's not clear what you are trying to do.
        I think you have some confusion in mind on what the mime data and types are vs what file association is.

        Could you describe a little bit more in detail where you are dragging this data to and what would you like to happen when dropped?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        F 1 Reply Last reply
        3
        • VRoninV VRonin

          Then it's not clear what you are trying to do.
          I think you have some confusion in mind on what the mime data and types are vs what file association is.

          Could you describe a little bit more in detail where you are dragging this data to and what would you like to happen when dropped?

          F Offline
          F Offline
          franc
          wrote on last edited by franc
          #5

          @VRonin What I would like to do is the following: I have a Qt Application which shows the content of a local directory.
          I want to take a file shown in the view, drag it outside the application, and drop it, for instance, on the Windows File Explorer or the Desktop.
          Say that the root of the QFileSystemModel is

          C:\Users\Admin\Desktop\test

          and I want the drop site being:

          C:\Users\Admin\Desktop

          and the drop file being:

          myFile.myType

          Once it is dropped, I want the program associated being launched automatically, opening that file.
          That's the reason why I need the mime type, but I do not know how this information is treated when a Qt application interacts with Windows environment . More in general, I do not know how a Qt application interacts with Windows environment.
          I would like to proceed step by step, and this justifies the incomplete question I made.

          JonBJ VRoninV 2 Replies Last reply
          0
          • F franc

            @VRonin What I would like to do is the following: I have a Qt Application which shows the content of a local directory.
            I want to take a file shown in the view, drag it outside the application, and drop it, for instance, on the Windows File Explorer or the Desktop.
            Say that the root of the QFileSystemModel is

            C:\Users\Admin\Desktop\test

            and I want the drop site being:

            C:\Users\Admin\Desktop

            and the drop file being:

            myFile.myType

            Once it is dropped, I want the program associated being launched automatically, opening that file.
            That's the reason why I need the mime type, but I do not know how this information is treated when a Qt application interacts with Windows environment . More in general, I do not know how a Qt application interacts with Windows environment.
            I would like to proceed step by step, and this justifies the incomplete question I made.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #6

            @franc

            Once it is dropped, I want the program associated being launched automatically, opening that file.
            That's the reason why I need the mime type

            I don't know about the drag/drop part, but why do you need the mime type to cause the associated application to open on the end file? That's what the Windows OS "shell open" does for you?

            F 1 Reply Last reply
            0
            • F franc

              @VRonin What I would like to do is the following: I have a Qt Application which shows the content of a local directory.
              I want to take a file shown in the view, drag it outside the application, and drop it, for instance, on the Windows File Explorer or the Desktop.
              Say that the root of the QFileSystemModel is

              C:\Users\Admin\Desktop\test

              and I want the drop site being:

              C:\Users\Admin\Desktop

              and the drop file being:

              myFile.myType

              Once it is dropped, I want the program associated being launched automatically, opening that file.
              That's the reason why I need the mime type, but I do not know how this information is treated when a Qt application interacts with Windows environment . More in general, I do not know how a Qt application interacts with Windows environment.
              I would like to proceed step by step, and this justifies the incomplete question I made.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #7

              @franc said in Drag a QFileSystemModel item and drop it into Windows Desktop:

              That's the reason why I need the mime type

              Nope that's wrong. You are trying to move a file so the mime type must be compatible with it. The event is not managed by the sender application but by the receiving object (the file explorer in your case) if it doesn't recognise the mime type then it will not accept the drop because it doesn't know what to do with it.

              All you can do is to call QDesktopServices::openUrl once the drop is completed

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              F 1 Reply Last reply
              3
              • JonBJ JonB

                @franc

                Once it is dropped, I want the program associated being launched automatically, opening that file.
                That's the reason why I need the mime type

                I don't know about the drag/drop part, but why do you need the mime type to cause the associated application to open on the end file? That's what the Windows OS "shell open" does for you?

                F Offline
                F Offline
                franc
                wrote on last edited by
                #8

                @JonB Thanks for the question. That's because the file myFile.myType should be opened with a specific handler application (say myApplication), which detects the mime application/myType.

                Summing up, I have four ingredients:

                1. a Qt Application which shows a directory in its central widget;
                2. a custom mime, application/myType, already contained in the Windows Register;
                3. a custom format, myFyle.myType;
                4. a second application, myApplication, which is registered as handler of the type myType.

                I want to pick myFile.myType from the Qt Application TreeView, drag it outside the Qt Application, drop it on Windows File Explorer, and once it is dropped, launching myApplication to open myFile.myType.

                JonBJ 1 Reply Last reply
                0
                • VRoninV VRonin

                  @franc said in Drag a QFileSystemModel item and drop it into Windows Desktop:

                  That's the reason why I need the mime type

                  Nope that's wrong. You are trying to move a file so the mime type must be compatible with it. The event is not managed by the sender application but by the receiving object (the file explorer in your case) if it doesn't recognise the mime type then it will not accept the drop because it doesn't know what to do with it.

                  All you can do is to call QDesktopServices::openUrl once the drop is completed

                  F Offline
                  F Offline
                  franc
                  wrote on last edited by
                  #9

                  @VRonin Sorry for the incoming out of topic: the File Manager should be able to recognize the mime type once I have added it on the Register, shouldn't it?

                  I thank you for the reference.

                  VRoninV 1 Reply Last reply
                  0
                  • F franc

                    @JonB Thanks for the question. That's because the file myFile.myType should be opened with a specific handler application (say myApplication), which detects the mime application/myType.

                    Summing up, I have four ingredients:

                    1. a Qt Application which shows a directory in its central widget;
                    2. a custom mime, application/myType, already contained in the Windows Register;
                    3. a custom format, myFyle.myType;
                    4. a second application, myApplication, which is registered as handler of the type myType.

                    I want to pick myFile.myType from the Qt Application TreeView, drag it outside the Qt Application, drop it on Windows File Explorer, and once it is dropped, launching myApplication to open myFile.myType.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #10

                    @franc
                    Sorry, I just don't understand questions as often phrased here as well as some of the Qt experts! I just read what is written and respond....

                    If you drop onto Windows Explorer, it is Windows Explorer which acts on that.

                    The stuff @VRonin is saying is right.

                    1 Reply Last reply
                    0
                    • F franc

                      @VRonin Sorry for the incoming out of topic: the File Manager should be able to recognize the mime type once I have added it on the Register, shouldn't it?

                      I thank you for the reference.

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #11

                      @franc said in Drag a QFileSystemModel item and drop it into Windows Desktop:

                      File Manager should be able to recognize the mime type once I have added it on the Register, shouldn't it?

                      @VRonin said in Drag a QFileSystemModel item and drop it into Windows Desktop:

                      I think you have some confusion in mind on what the mime data and types are vs what file association is.

                      The mime type is not the file extension. The mime type text/uri-list is recognised by the file system as a list of files that it can copy/move/create a link to.

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      3

                      • Login

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