[SOLVED] Drag 'n drop a file in an editor: different behaviour on Linux compared to Windows / Mac OS X

  • Hi,

    My application has an editor and supports drag and drop. (I use QScintilla for my editor, but the problem occurs with QTextEdit, so it doesn't seem to be widget dependent.)

    Now, if I select some text (from another application), drag it and drop it on my application's editor, then the text gets inserted (as expected). However, if I select some files (from a file manager of sorts), drag them and drop them on my application's editor, then on Windows and Mac OS X, the dropping of the files gets handled by my application (which opens the files in its editor) while on Linux, the dropping of the files results in their URL being inserted (e.g. file:///home/me/myFile).

    So, how come the behaviour on Linux is different from that on Windows and Mac OS X? Anyone, any idea?

    Cheers, Alan.

  • That would depend on the implementation of your drop methods as well as on the contentes of the drag itself. Did you have a look what's inside the drag with the dropsite example from the sources?

  • Yes, I had checked the format of the dropped data and indeed on Windows/Mac OS X, the data had a text/uri-list format while on Linux it also had text/plain format.

    Anyway, for some reason, your message made me think of dragEnterEvent and testing the format of the data there, and decide whether to accept the event or not. In other words, I have created a new class which inherits from QsciScintilla and which overrides dragEnterEvent:

    @void QScintilla::dragEnterEvent(QDragEnterEvent *pEvent)
    if (!pEvent->mimeData()->hasFormat("text/uri-list"))

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.