How to drag and drop OS Files with Icons and textes?
-
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:
( now I have green circle, I would like to have blue circle ( Of course the black background is because I do printscreen from Desktop :) ) )
-
@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 Googleqlabel 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? -
@JonB QPushButton does allow both.
@TomNow99 you can reimplement the handling of dropped data to fill the model with want you want.