[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: Various Issues with PyQt6
From:       RoadrunnerWMC <roadrunnerwmc () gmail ! com>
Date:       2021-02-26 19:59:58
Message-ID: CADLpnNvbi2cH_-v1qxxPem4ckP=StC-DLtbJa95OqRakjZG+3g () mail ! gmail ! com
[Download RAW message or body]

Thanks for fixing the StandardButtons bug. I wasn't sure if the other two
would be PyQt or Qt issues; I'll look into it at the Qt level, then.

On Fri, Feb 26, 2021 at 10:10 AM Phil Thompson <phil@riverbankcomputing.com>
wrote:

> On 26/02/2021 04:13, RoadrunnerWMC wrote:
> > Hi again Phil,
> >
> > I just installed PyQt 6.0.2. The problems from my previous email are
> > fixed
> > now (thanks!) and my application is able to launch. I am having a few
> > new
> > issues now, though.
> >
> > Here's the main one:
> >
> >     from PyQt6 import QtCore, QtGui, QtWidgets
> >     app = QtWidgets.QApplication([])
> >
> >     mbox = QtWidgets.QMessageBox()
> >     mbox.setStandardButtons(QtWidgets.QMessageBox.StandardButtons.Yes |
> > QtWidgets.QMessageBox.StandardButtons.No)
> >     ret = mbox.exec()
> >
> >     # The return value is an integer, but
> > QtWidgets.QMessageBox.StandardButtons
> >     # can't be converted or compared to integers.
> >
> >     # This prints False no matter which button you clicked:
> >     print(ret == QtWidgets.QMessageBox.StandardButtons.Yes)
> >
> >     # TypeError: int() argument must be a string, a bytes-like object
> > or a
> > number, not 'StandardButtons'
> >     int(QtWidgets.QMessageBox.StandardButtons.Yes)
> >
> >     # TypeError: unsupported operand type(s) for &: 'int' and
> > 'StandardButtons'
> >     print(ret & QtWidgets.QMessageBox.StandardButtons.Yes)
> >
> > As far as I can tell, there's no way to check the return value of
> > `QtWidgets.QMessageBox.exec()` without hardcoding integer values
> > (yuck).
> > One way to fix it would be to change `.exec()`'s return type to
> > `QtWidgets.QMessageBox.StandardButtons`, but since the integer values
> > of
> > the enum are officially publicly documented (
> > https://doc.qt.io/qt-6/qmessagebox.html#StandardButton-enum), my guess
> > is
> > that adding support for int comparisons to the `StandardButtons` class
> > would be a better solution. Or maybe there already is a way to do this
> > comparison and I just don't see it?
>
> That will be fixed in the next snapshot.
>
> > A second issue:
> >
> >     from PyQt6 import QtCore, QtGui, QtWidgets
> >     app = QtWidgets.QApplication([])
> >     folder = QtWidgets.QFileDialog.getExistingDirectory(None, 'Select a
> > folder')
> >     print(folder)
> >
> > For whatever reason, this actually creates a *file*-selection dialog,
> > which
> > doesn't let me choose a folder. (Platform is KDE Neon (Ubuntu 20.04),
> > if it
> > helps.)
>
> I've only tested on macOS but that puts up the correct dialog so it is
> unlikely to be a PyQt issue.
>
> > One more issue I found on 6.0.1 after my previous email -- though
> > unfortunately without a way to trigger it consistently -- is that
> > sometimes
> > `QMainWindow.restoreState()` or `QMainWindow.restoreGeometry()` (not
> > sure
> > which) crashes if the pre-existing state (or geometry) was saved by
> > PyQt5.
> >
> > The best workaround I can think of is to append the PyQt version name
> > ("PyQt5"/"PyQt6") to the application name passed to the QSettings
> > constructor, thus preventing PyQt6 from ever trying to read PyQt5's
> > settings and vice versa. Luckily, my application has very few settings
> > and
> > I don't expect anyone to switch back and forth between PyQt versions,
> > so
> > this won't be a big problem. It's still not really ideal, though.
> >
> > Is this crash considered a bug? If not, is there a better way for me to
> > handle this situation?
>
> Again I can't see how that is a PyQt issue rather than a Qt issue.
>
> Phil
>

[Attachment #3 (text/html)]

<div dir="ltr">Thanks for fixing the  StandardButtons bug. I wasn&#39;t sure if the \
other two would be PyQt or Qt issues; I&#39;ll look into it at the Qt level, \
then.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb \
26, 2021 at 10:10 AM Phil Thompson &lt;<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 26/02/2021 04:13, \
RoadrunnerWMC wrote:<br> &gt; Hi again Phil,<br>
&gt; <br>
&gt; I just installed PyQt 6.0.2. The problems from my previous email are <br>
&gt; fixed<br>
&gt; now (thanks!) and my application is able to launch. I am having a few <br>
&gt; new<br>
&gt; issues now, though.<br>
&gt; <br>
&gt; Here&#39;s the main one:<br>
&gt; <br>
&gt;        from PyQt6 import QtCore, QtGui, QtWidgets<br>
&gt;        app = QtWidgets.QApplication([])<br>
&gt; <br>
&gt;        mbox = QtWidgets.QMessageBox()<br>
&gt;        mbox.setStandardButtons(QtWidgets.QMessageBox.StandardButtons.Yes |<br>
&gt; <a href="http://QtWidgets.QMessageBox.StandardButtons.No" rel="noreferrer" \
target="_blank">QtWidgets.QMessageBox.StandardButtons.No</a>)<br> &gt;        ret = \
mbox.exec()<br> &gt; <br>
&gt;        # The return value is an integer, but<br>
&gt; QtWidgets.QMessageBox.StandardButtons<br>
&gt;        # can&#39;t be converted or compared to integers.<br>
&gt; <br>
&gt;        # This prints False no matter which button you clicked:<br>
&gt;        print(ret == QtWidgets.QMessageBox.StandardButtons.Yes)<br>
&gt; <br>
&gt;        # TypeError: int() argument must be a string, a bytes-like object <br>
&gt; or a<br>
&gt; number, not &#39;StandardButtons&#39;<br>
&gt;        int(QtWidgets.QMessageBox.StandardButtons.Yes)<br>
&gt; <br>
&gt;        # TypeError: unsupported operand type(s) for &amp;: &#39;int&#39; and<br>
&gt; &#39;StandardButtons&#39;<br>
&gt;        print(ret &amp; QtWidgets.QMessageBox.StandardButtons.Yes)<br>
&gt; <br>
&gt; As far as I can tell, there&#39;s no way to check the return value of<br>
&gt; `QtWidgets.QMessageBox.exec()` without hardcoding integer values <br>
&gt; (yuck).<br>
&gt; One way to fix it would be to change `.exec()`&#39;s return type to<br>
&gt; `QtWidgets.QMessageBox.StandardButtons`, but since the integer values <br>
&gt; of<br>
&gt; the enum are officially publicly documented (<br>
&gt; <a href="https://doc.qt.io/qt-6/qmessagebox.html#StandardButton-enum" \
rel="noreferrer" target="_blank">https://doc.qt.io/qt-6/qmessagebox.html#StandardButton-enum</a>), \
my guess <br> &gt; is<br>
&gt; that adding support for int comparisons to the `StandardButtons` class<br>
&gt; would be a better solution. Or maybe there already is a way to do this<br>
&gt; comparison and I just don&#39;t see it?<br>
<br>
That will be fixed in the next snapshot.<br>
<br>
&gt; A second issue:<br>
&gt; <br>
&gt;        from PyQt6 import QtCore, QtGui, QtWidgets<br>
&gt;        app = QtWidgets.QApplication([])<br>
&gt;        folder = QtWidgets.QFileDialog.getExistingDirectory(None, &#39;Select \
a<br> &gt; folder&#39;)<br>
&gt;        print(folder)<br>
&gt; <br>
&gt; For whatever reason, this actually creates a *file*-selection dialog, <br>
&gt; which<br>
&gt; doesn&#39;t let me choose a folder. (Platform is KDE Neon (Ubuntu 20.04), <br>
&gt; if it<br>
&gt; helps.)<br>
<br>
I&#39;ve only tested on macOS but that puts up the correct dialog so it is <br>
unlikely to be a PyQt issue.<br>
<br>
&gt; One more issue I found on 6.0.1 after my previous email -- though<br>
&gt; unfortunately without a way to trigger it consistently -- is that <br>
&gt; sometimes<br>
&gt; `QMainWindow.restoreState()` or `QMainWindow.restoreGeometry()` (not <br>
&gt; sure<br>
&gt; which) crashes if the pre-existing state (or geometry) was saved by <br>
&gt; PyQt5.<br>
&gt; <br>
&gt; The best workaround I can think of is to append the PyQt version name<br>
&gt; (&quot;PyQt5&quot;/&quot;PyQt6&quot;) to the application name passed to the \
QSettings<br> &gt; constructor, thus preventing PyQt6 from ever trying to read \
PyQt5&#39;s<br> &gt; settings and vice versa. Luckily, my application has very few \
settings <br> &gt; and<br>
&gt; I don&#39;t expect anyone to switch back and forth between PyQt versions, <br>
&gt; so<br>
&gt; this won&#39;t be a big problem. It&#39;s still not really ideal, though.<br>
&gt; <br>
&gt; Is this crash considered a bug? If not, is there a better way for me to<br>
&gt; handle this situation?<br>
<br>
Again I can&#39;t see how that is a PyQt issue rather than a Qt issue.<br>
<br>
Phil<br>
</blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic