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. get control back on dragged items
Forum Updated to NodeBB v4.3 + New Features

get control back on dragged items

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 156 Views
  • 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.
  • 4 Offline
    4 Offline
    4n0d3v
    wrote on last edited by 4n0d3v
    #1

    hey guys,
    I got an issue with Qt 5.15.2 and items dragged from a list...

    • the code :
      draglist.h
    #define DRAGLIST_H
    
    #include <QListWidget>
    #include <QMimeData>
    
    class DragList : public QListWidget
    {
        Q_OBJECT
    public:
        explicit DragList(QWidget *parent = nullptr);
    
    protected:
        QMimeData *mimeData(const QList<QListWidgetItem*> items) const
        {
            QString s="";
            foreach (auto item, items)
                s += item->text() + "\n";
            QMimeData *md = QListWidget::mimeData(items);
            md->setText(s.left(s.length()-1));
            return md;
        }
    };
    
    #endif // DRAGLIST_H
    

    draglist.cpp

    #include "draglist.h"
    
    DragList::DragList(QWidget *parent)
        : QListWidget(parent)
    {
    }
    

    I use that very simple class to be able to drag items (url actually) from a QListWidget
    So you can easily reproduce : just throw a QListWidget on a form and check its dragEnabled field, change its dragDropMode to DragOnly and promote it to DragList and voilà !
    oh yes just add an entry to the list, let's say "https://www.google.com"

    .

    • The issue :

    if you drag that item (https://www.google.com) and drop it into a Chrome window, it opens a google page and your item is still present into the QListWidget component. But do the very same thing with a Firefox window and your item disappears from the list.

    .

    • Solutions ?

    Is there a way to tells Qt that items of this QlistWidget won't be transferred but only copied - no matter what - ? (knowing we already got the defaultDropAction of that QListWidget set to CopyAction, but i guess this property is about things dropped into that list, not about the action to take after one of its items was dropped)
    Or is there a way to intercept the drop message to ignore it (as somehow chrome says to my Qt app "i copied that item" while firefox says "thank u for givin me that item, hope u won't miss it too much ;)")

    Thank you for your time, guys and hopefully your solutions :)

    By the way i know as a workaround i might answer to the event of selection changing or item deletion by simply saving the selection before the drag and re-add the potentially missing items if needed, but I would like a more elegant solution which doesn't involve repairing the damage, but preventing it

    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