how can i drag a file from windows explorer or desktop to a Qt Widget(eg. QTreeWidget) ?
-
how can i drag a file from windows explorer or desktop to a Qt Widget(eg. QTreeWidget) ?
-
What is a Windows Resource Manager? I don't think you mean this cause it's a server feature and doesn't have any files in it.
-
modified, thank you !
-
There are basically 3 steps:
Enable drag&drop suport on your widget:
treeWidget->setAcceptDrops(true);
Override drag enter event and check if it carries urls:
void YourTreeWidget::dragEnterEvent(QDragEnterEvent * evt) { if(evt->mimeData()->hasUrls()) evt->accept(); }
NOTE:The above accepts any kind of urls. If you want to be more specific you can inspect the urls to check if they are file/directory/web urls and accept only what you want.
Last step is to override drop event and act on the urls:
void YourTreeWidget::dropEvent(QDropEvent * evt) { auto urls = evt->mimeData()->urls(); foreach(auto url, urls) { //do stuff to tree widget based on the file url } }
-
thank you very much.
but how can i inspect the urls to check if they are file/directory/web urls ?
is there any examples or docs ? -
-
-
thank you, mainly file/directory/ :)