enthought / enthought/traitsui
QtGui.QStyleOptionSlider: implicit conversion to float fails with Python 3.10
- Dominant language
- Python
- Stars
- 306
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
With Python 3.10, using a traitsui `BoundsEditor` for a `Range` fails:
```python
from traits.api import *
from traitsui.api import *
from traitsui.qt4.extra.bounds_editor import BoundsEditor
class Test(HasTraits):
val = Range(0.3, 10.5)
_xmin = Float(5.0)
_xmax = Float(10.0)
view = View(
UItem(
'val',
editor=BoundsEditor(
low_name='_xmin',
high_name='_xmax',
format='%.2f')
)
)
Test().configure_traits()
```
```
Traceback (most recent call last):
File ".../lib/python3.10/site-packages/traitsui/qt4/extra/range_slider.py", line 81, in paintEvent
opt.sliderPosition = value
TypeError: 'float' object cannot be interpreted as an integer
```
The same code works in Python 3.9.
In range_slider.py, the slider position appears to be set like so:
```python
opt = QtGui.QStyleOptionSlider()
opt.sliderPosition = value
```
This appears to be the reason for the failure because `value` is a float and implicit conversion fails in Python 3.10.
## Python 3.9
```python
Python 3.9.10 (main, Mar 2 2022, 14:03:08)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyface.qt import QtGui
>>> QtGui.QStyleOptionSlider().sliderValue = 5
>>> QtGui.QStyleOptionSlider().sliderValue = 5.5
:1: DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
```
## Python 3.10
```python
Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyface.qt import QtGui
>>> QtGui.QStyleOptionSlider().sliderValue = 5
>>> QtGui.QStyleOptionSlider().sliderValue = 5.5
Traceback (most recent call last):
File "", line 1, in
TypeError: 'float' object cannot be interpreted as an integer
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.