[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Faulty Drag Data under QT?


On Thu, 12 Feb 2026 at 11:35, Bruce Steers <bsteers4@xxxxxxxxx> wrote:

>
> On Thu, 12 Feb 2026, 10:52 Claus Dietrich, <claus.dietrich@xxxxxxxxxx>
> wrote:
>
>> When I drag a file from Nemo and drop it into my app (gb.gui.qt), the
>> following 3 lines ....
>>
>> Public Sub Form_Drop()
>>      Print "Drag.Type:"; Drag.Type
>>      Print Drag.Data
>> End
>>
>> deliver following strange output in the IDE console:
>> Drag.Type: 1
>> 0:-8:436:20e/claus/Bilder/Bildschirmfoto%20vom%202026-02-08%2016-09-59.png
>>
>> When I switch from gb.gui.qt to GTK+3 the IDE console output is
>> Drag.Type: 1
>> file:///home/claus/Bilder/Bildschirmfoto%20vom%202026-02-08%2016-09-59.png
>>
>> Do we have a bug here?
>> Best regards
>> Claus
>>
>
> No.
> Drag.Data is the raw data and it's format can vary depending on toolkit.
>
> You should avoid Drag.Data and use Drag.Paste
>
> Then you should get better results.
>
> Also remember Drag.Type is used mostly only to define between drag.image
> or some kind of text format.
>
> The format to use for drag.paste (the mime format) will be in either
> Drag.Format or one of Drag.Formats[]
>
> Drag.Type equaling Drag.Text does not mean you're going to get text/plain
> mime type.
>
> Respects
> BruceS
>


Ps, the best way to handle desktop file drops is to check for text/uri-list
in the formats (it might not be the Drag.Format property)

For example, the following code....  (using MATE desktop/Caja and dropping
a png file)
Public Sub Form_Drop()

  Dim aFiles As String[]
  Print Drag.Type
  Print Drag.Data
  Print Drag.Format
  If Drag.Formats.Exist("text/uri-list") Then
    aFiles = Drag.Paste("text/uri-list")
    Print aFiles.Join("\n")
  Endif

End

Gives the following results...

GTK3..
1
file:///home/bonus/Desktop/UseEdit/.public/icons8-pencil-drawing-48.png

x-special/mate-icon-list
x-special/mate-icon-list; text/uri-list; text/plain;charset=utf-8;
text/plain
/home/bonus/Desktop/UseEdit/.public/icons8-pencil-drawing-48.png

QT...
1
-49:-48:64:64bonus/Desktop/UseEdit/.public/icons8-pencil-drawing-48.png

x-special/mate-icon-list
x-special/mate-icon-list; text/uri-list; text/plain;
text/plain;charset=utf-8
/home/bonus/Desktop/UseEdit/.public/icons8-pencil-drawing-48.png

So you will note.  Drag.Data is different with the toolkits and Drag.Format
is NOT text/uri-list but text/uri-list does exist in Drag.Formats[]
Then Drag.Paste("text/uri-list") gives us all we want.
it processes Drag.Data so that you don't have to
If you want to deal with the raw Drag.Data directly you will have to
process it yourself to handle each toolkits differences.  (i'd recommend
avoiding it in most cases)

Drag.Format itself will vary depending on the desktop but text/uri-list
should be in Formats[] for file drops on all desktops.

Respects
BruceS

References:
Faulty Drag Data under QT?Claus Dietrich <claus.dietrich@xxxxxxxxxx>
Re: Faulty Drag Data under QT?Bruce Steers <bsteers4@xxxxxxxxx>