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">> Hi,<br>>=C2=A0<br>> I've changed your code:=
<br>>=C2=A0<br>>=C2=A0 =C2=A0 =C2=A0def dropEvent(self, event: QDropE=
vent):<br>>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 data =3D eve=
nt.mimeData()<br>>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print=
("data.text():", data.text(), type(data.text()))<br>>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print("data.data('text/pla=
in'):", str(data.data('text/plain')),<br>>=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('text/plain')))<br>>=C2=A0<br>>=C2=A0And t=
he result:<br>>=C2=A0<br>>=C2=A0data.text(): D=C3=A9j=C3=A0-vu <cl=
ass 'str'><br>>=C2=A0data.data('text/plain'): b'D=
\xc3\xa9j\xc3\xa0-vu' <class<br>>=C2=A0'PyQt5.QtCore.QByteArr=
ay'><br>>=C2=A0<br>>=C2=A0On Ubuntu Mate, the text "D=C3=
=A9j=C3=A0-vu" is dragged from Pluma (old Gedit)<br>>=C2=A0<br>>=
=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 'tex=
t/plain' 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--