Handling of flags in PyQt5 / PyQt6

Phil Thompson phil at riverbankcomputing.com
Wed Mar 17 09:50:03 GMT 2021

On 16/03/2021 16:16, Florian Bruhin wrote:
> Hey again,
> On Tue, Mar 16, 2021 at 04:55:42PM +0100, Florian Bruhin wrote:
>> Or as a more compact overview:
>> PyQt5: enum only (or unscoped)
>> PyQt6: flags only
>> PySide2: flags only (or unscoped)
>> PySide6: flags only (or unscoped)
> Well, looks like I successfully confused myself with the Alignment vs.
> AlignmentFlag names. Let me try again, please disregard the earlier
> mail.
> PySide2 and PySide6 both allow access via the *enum* name only. To make
> it clearer, let me try again with Qt.Orientation (enum) vs.
> Qt.Orientations (flag):
> PyQt5:   Qt.Horizontal (unscoped) or Qt.Orientation.Horizontal (enum)
> PyQt6:   Qt.Orientations.Horizontal (flag)
> PySide2: Qt.Horizontal (unscoped) or Qt.Orientation.Horizontal (enum)
> PySide6: Qt.Horizontal (unscoped) or Qt.Orientation.Horizontal (enum)
> So PyQt6 seems like the "oddball" here. I'm fine with using scoped
> values everywhere, but I think PyQt6 should support accessing flag
> values via the enum type, so that it's possible to write code which
> works with PyQt5 and PyQt6 (or PyQt6 and PySide6).

Generally the difference between the enum name and the flag name is that 
the latter is the plural of the former. I felt that the plural form was 
the better name to use as it more accurately describes the usage of the 
"thing" - its a clue to the programmer that members can be ored 
together. Taken in isolation I think that that was the right choice.

However, taking PyQt5 into account then I agree that the benefit is 
questionable, especially considering how similar the Qt5 and Qt6 APIs 
actually are. I'm happy to switch to using the enum name in v6.1 - 
assuming nobody is going to argue otherwise.


More information about the PyQt mailing list