Re: Issues with QMimeData.text()

Bryce Beagle <[email protected]> Sat, 13 Jun 2020 13:43:48 -0700
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <CAKKt4mZRpENMc0TjafeNdiL=AhGzHXaLG0zyNqLduddu9j+LWA@mail.gmail.com>
--000000000000c49ade05a7fd4052
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

> Hi,
>
> I've changed your code:
>
>     def dropEvent(self, event: QDropEvent):
>         data =3D event.mimeData()
>         print("data.text():", data.text(), type(data.text()))
>         print("data.data('text/plain'):", str(data.data('text/plain')),
>                type(data.data('text/plain')))
>
> And the result:
>
> data.text(): D=C3=A9j=C3=A0-vu <class 'str'>
> data.data('text/plain'): b'D\xc3\xa9j\xc3\xa0-vu' <class
> 'PyQt5.QtCore.QByteArray'>
>
> On Ubuntu Mate, the text "D=C3=A9j=C3=A0-vu" is dragged from Pluma (old G=
edit)
>
> Vincent

I apologize for being as clear as I would have liked to be in my original
email, but the issue I presented only occurs from some sources. I can
drag-and-drop perfectly fine from Gedit. Other sources, such as Chromium,
Slack, and PyCharm do not work (i.e. QMimeData.text() only returns an empty
string), even though they provide a 'text/plain' format.

Another side note, it seems strange to me that QMimeData.data() returns a
QByteArray instead of a python bytes/bytearray object.

Thanks,
Bryce

--000000000000c49ade05a7fd4052
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">&gt; Hi,<br>&gt;=C2=A0<br>&gt; I&#39;ve changed your code:=
<br>&gt;=C2=A0<br>&gt;=C2=A0 =C2=A0 =C2=A0def dropEvent(self, event: QDropE=
vent):<br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 data =3D eve=
nt.mimeData()<br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print=
(&quot;data.text():&quot;, data.text(), type(data.text()))<br>&gt;=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print(&quot;data.data(&#39;text/pla=
in&#39;):&quot;, str(data.data(&#39;text/plain&#39;)),<br>&gt;=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 type(data.data(&#39;text/plain&#39;)))<br>&gt;=C2=A0<br>&gt;=C2=A0And t=
he result:<br>&gt;=C2=A0<br>&gt;=C2=A0data.text(): D=C3=A9j=C3=A0-vu &lt;cl=
ass &#39;str&#39;&gt;<br>&gt;=C2=A0data.data(&#39;text/plain&#39;): b&#39;D=
\xc3\xa9j\xc3\xa0-vu&#39; &lt;class<br>&gt;=C2=A0&#39;PyQt5.QtCore.QByteArr=
ay&#39;&gt;<br>&gt;=C2=A0<br>&gt;=C2=A0On Ubuntu Mate, the text &quot;D=C3=
=A9j=C3=A0-vu&quot; is dragged from Pluma (old Gedit)<br>&gt;=C2=A0<br>&gt;=
=C2=A0Vincent<br><div><br></div><div>I apologize for being as clear as I wo=
uld have liked to be in my original email, but the issue I presented only o=
ccurs from some sources. I can drag-and-drop perfectly fine from Gedit. Oth=
er sources, such as Chromium, Slack, and PyCharm do not work (i.e. QMimeDat=
a.text() only returns an empty string), even though they provide a &#39;tex=
t/plain&#39; format.</div><div><br></div><div>Another side note, it seems s=
trange to me that QMimeData.data() returns a QByteArray instead of a python=
 bytes/bytearray object.=C2=A0</div><div><br></div><div>Thanks,</div><div>B=
ryce</div></div>

--000000000000c49ade05a7fd4052--