more enum breakage

Phil Thompson phil at riverbankcomputing.com
Sun Jun 19 10:13:09 BST 2022


On 19/06/2022 05:02, Kovid Goyal wrote:
>> From the gift that keeps on giving department:
> 
> Returning Qt.ItemDataRole.TextAlignmentRole from the data() method of
> models does not work in PyQt6, one has to return an integer not an enum
> for it to work. So, for example:
> 
>    return Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter
> 
> results in text rendered by Qt at top left corner, but
> 
>    return (Qt.AlignmentFlag.AlignHCenter | 
> Qt.AlignmentFlag.AlignVCenter).value
> 
> works as expected.

It depends on wether we want the type of the value to be retained by 
QVariant. With the current behaviour the following...

QVariant(Qt.AlignmentFlag.AlignHCenter).value() is 
Qt.QAlignmentFlag.QAlignHCenter

...is true.

If QVariant was changed to automatically convert an enum member to an 
int then that type information would be lost. I'm not sure how important 
that is???

Phil


More information about the PyQt mailing list