[PyQt] DeprecationWarning using TextAlignmentRole in a QStandardItem subclass

Phil Thompson phil at riverbankcomputing.com
Sun Jan 19 11:42:31 GMT 2020


On 18/01/2020 12:15, Sibylle Koczian wrote:
> If I execute the following script I get this warning:
> 
> Warning (from warnings module):
>   File "D:\Sibylle\Src\PythonVersuche\PyQt\test_warning.py", line 77
>     app.exec_()
> DeprecationWarning: an integer is required (got type Alignment).
> Implicit conversion to integers using __int__ is deprecated, and may be
> removed in a future version of Python.
> 
> The script works as expected, but of course I want to know what is
> happening here. The warning doesn't appear if I comment out the data()
> method of the model class, and it doesn't appear if I run the script
> with test_model() instead of main(). I suppose in that second case the
> TextAlignmentRole is not used, right?
> 
> I tried to google the warning but got only some entries about the same
> sort of warning in numpy regarding conversions from float to int.
> 
> Python version is 3.8.1, PyQt5 is version 5.14.1 on windows 10, same
> versions on ArchLinux.
> 
> ...

It should be fixed in tonight's PyQt snapshot.

In the meantime if you want to avoid the warning then do as it suggests 
and make the conversion explicit, ie. change the 'return' statement 
to...

     return int(h_align | QtCore.Qt.AlignVCenter)

Thanks,
Phil


More information about the PyQt mailing list