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. Drag and drop .exe to create icon bar
Forum Updated to NodeBB v4.3 + New Features

Drag and drop .exe to create icon bar

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.2k 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.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    What I am trying to do is make a quick launch bar in one of my applications that can spawn an application. What I would like to do is be able to drag a application executable into a QFrame (which is into a vbox layout for the icon buttons) and recognize the drop. Then add the image of the executable into the bar.

    I think from there it would be easy to create a QToolButton that spawns a QProcess when the application button is clicked in icon bar.

    I guess I am looking for some guidance on how I would go about doing the drag and drop and the image processing of the executable. Or if there is something similar out there...

    Thank you in advance!

    Edit: from what I have read so far, I have set up a subclass of a QFrame in hope of being able to have a drag and drop event. Still unsure of the best way to do this though...

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      You just have to re-implement dragEnterEvent() and dropEvent() in your widget in order to accept and process files that have been dropped onto your application via Drag&Drop. If a file gets dropped onto the application (e.g. from Windows Explorer), you can get the path to that file. In my application I use code like this:

      @/*

      • File dragged over window
        */
        void MainWindow::dragEnterEvent(QDragEnterEvent *event)
        {
        QStringList formats = event->mimeData()->formats();

      /accept drag if suitable/
      if(formats.contains("application/x-qt-windows-mime;value="FileNameW"", Qt::CaseInsensitive) && formats.contains("text/uri-list", Qt::CaseInsensitive))
      {
      event->acceptProposedAction();
      }
      }

      /*

      • File dropped onto window
        */
        void MainWindow::dropEvent(QDropEvent *event)
        {
        QStringList droppedFiles;
        QList<QUrl> urls = event->mimeData()->urls();

      while(!urls.isEmpty())
      {
      QUrl currentUrl = urls.takeFirst();
      QFileInfo file(currentUrl.toLocalFile());
      if(!file.exists())
      {
      continue;
      }
      if(file.isFile())
      {
      droppedFiles << file.canonicalFilePath();
      }
      }

      if(!droppedFiles.isEmpty())
      {
      /* do something with the dropped files */
      }
      }@

      I don't think you can get an Icon from the dropped file directly. But once you have path to the file, you could use the QFileIconProvider class to get a QIcon for that file...

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vezprog
        wrote on last edited by
        #3

        Perfect! This is awesome stuff! So I guess I have another question, can the drag drop event be used on any object by subclassing?

        I think I am going to implement it into a QFrame with a vbox layout to they will align when dragged in.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          dragEnterEvent, dropEvent etc. are methods of QWidget, so in principle, you can use that everywhere. Some of the more advanced widgets provide some default implementation for drag/drop with some more advanced API. The item view classes like [[Doc:QTreeView]] or [[Doc:QTextEdit]] come into mind here.

          http://www.catb.org/~esr/faqs/smart-questions.html

          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