Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to drag and drop OS Files with Icons and textes?
TomNow99 last edited by
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?
( now I have green circle, I would like to have blue circle ( Of course the black background is because I do printscreen from Desktop :) ) )
JonB last edited by JonB
While you wait for a better answer:
I believe that a
QLabelwill 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
QPushButtonallow both an image and text?
@JonB QPushButton does allow both.