Qt-UI

Drag and Dropping UR Ls

Drag and Drop | | A Painter Application

(:Drag and Dropping URLs:)

If we want to accept only a specific type of items, for example URLs resp. files being dropped into the widget, we check the item type in the drop event and accept the drop if it matches:

void ViewerWindow::dropEvent(QDropEvent *event)
{
   const QMimeData *mimeData = event->mimeData();

   if (mimeData->hasUrls())
   {
      event->acceptProposedAction();

      QList<QUrl> urlList = mimeData->urls();

      for (int i=0; i<urlList.size(); i++)
      {
         QUrl qurl = urlList.at(i);

         // run appropriate action for each dropped url here
      }
   }
}


Drag and Drop | | A Painter Application

Options: