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. How to drag and drop OS Files with Icons and textes?
Forum Updated to NodeBB v4.3 + New Features

How to drag and drop OS Files with Icons and textes?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 408 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
    TomNow99
    wrote on last edited by
    #1

    Hello,

    I would like to drag and drop Windows files for example txt files / image files.

    I can drag os file and drop it into QListWidget. But if I do that I get only path to this file. I would like to drag os file and drop it and get icon with name ( not full path - only name ). Of course I can't drop it into QListWidget. So I create own QWidget with QLabels. When I move draged files I get their names, so I can do:

        QFileIconProvider icon;
        QFileInfo fileinfo(R"(pathToFile)");
        QIcon ic=icon.icon(fileinfo);
        label->setPixmap(ic.pixmap(100,100).scaled(100,100));
    

    Using this code I get only icons with no names.

    Is there a simple way to do this what I want?

    Picture:
    example.png

    ( now I have green circle, I would like to have blue circle ( Of course the black background is because I do printscreen from Desktop :) ) )

    JonBJ 1 Reply Last reply
    0
    • T TomNow99

      Hello,

      I would like to drag and drop Windows files for example txt files / image files.

      I can drag os file and drop it into QListWidget. But if I do that I get only path to this file. I would like to drag os file and drop it and get icon with name ( not full path - only name ). Of course I can't drop it into QListWidget. So I create own QWidget with QLabels. When I move draged files I get their names, so I can do:

          QFileIconProvider icon;
          QFileInfo fileinfo(R"(pathToFile)");
          QIcon ic=icon.icon(fileinfo);
          label->setPixmap(ic.pixmap(100,100).scaled(100,100));
      

      Using this code I get only icons with no names.

      Is there a simple way to do this what I want?

      Picture:
      example.png

      ( now I have green circle, I would like to have blue circle ( Of course the black background is because I do printscreen from Desktop :) ) )

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

      @TomNow99
      While you wait for a better answer:

      I believe that a QLabel will only show one of either an icon or text, not both. See question https://stackoverflow.com/questions/10533838/displaying-a-standard-icon-and-text-in-qlabel and answer there, or https://stackoverflow.com/questions/47856872/how-to-add-both-an-image-and-text-to-a-qlabel, for possibilities. You can find these and others via Google qlabel icon plus text.

      Alternatively, and this is just a hunch you'd have to check out, does a QPushButton allow both an image and text?

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

        @JonB QPushButton does allow both.

        @TomNow99 you can reimplement the handling of dropped data to fill the model with want 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

        • Login

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