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 and drop image from application to windows explorer

Drag and drop image from application to windows explorer

Scheduled Pinned Locked Moved Unsolved General and Desktop
dragdrop
4 Posts 4 Posters 2.9k 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.
  • A Offline
    A Offline
    AliReza Beytari
    wrote on 25 May 2016, 05:35 last edited by AliReza Beytari
    #1

    Hi guys!
    There is a QLabel on my ui form which is as an image (I set "pixmap" property). So now, I want to let the use to drag and drop this image to Windows Explorer and shop graphic application (like Photoshop). How to do that?!

    R 1 Reply Last reply 25 May 2016, 07:03
    0
    • J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 25 May 2016, 06:52 last edited by
      #2

      Did you read http://doc.qt.io/qt-5.6/dnd.html ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 25 May 2016, 06:57 last edited by
        #3

        HI
        and for
        "shop graphic application"
        you can use
        http://doc.qt.io/qt-5/qdesktopservices.html

        and openUrl

        "If the URL is a reference to a local file (i.e., the URL scheme is "file") then it will be opened with a suitable application instead of a Web browser."

        That will open the app user has for the image type.

        1 Reply Last reply
        0
        • A AliReza Beytari
          25 May 2016, 05:35

          Hi guys!
          There is a QLabel on my ui form which is as an image (I set "pixmap" property). So now, I want to let the use to drag and drop this image to Windows Explorer and shop graphic application (like Photoshop). How to do that?!

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 25 May 2016, 07:03 last edited by raven-worx
          #4

          @AliReza-Beytari

          So to enable drops to the filesystem you should add a file urls (using QMimeData::setUrls() for example).
          For photoshop it might be enough to set a image on the mimedata (using QMimeData::setPixmap())

          Take a look at the Delayed encoding example.

          The interesting part here is the QMimeData::retrieveData() overload. This method gets called when a drop happens.

          So when a drop to the filesystem happens the mimedata requests the data and calls retrieveData(). In there you write your pixmap data to a temporary image file. For that you can use QTemporaryFile class for example. Write the data to the temporary file and return the url to the file. Mime-Type: "text/uri-list"

          Analog for the pixmap image. Simply return the QPixmap. Mime-Type: "image/png"
          Actually it could also be necessary to return the PNG binary data. I am not sure. This can be done like this:

          QPixmap pixmap;
          QByteArray data;
          QBuffer buffer(&data);
          buffer.open(QIODevice::WriteOnly);
          pixmap.save(&buffer, "PNG");
          buffer.close();
          

          The advantage of this approach is that you only create the drop data when necessary. Especially the temp file used for drops to the filesystem.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2

          1/4

          25 May 2016, 05:35

          • 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