enthought / pyface

pyface: traits-capable windowing framework
Other
105 stars 55 forks source link

Bug report: Error with `QFontMetrics` on PySide6 in console widget #1146

Closed corranwebster closed 2 years ago

corranwebster commented 2 years ago

Environment

OS: all Python version: 3.8 Toolkit: Qt Qt API: PyQt6/PySide6

Description

When pressing the tab key in the Mayavi Python console, we get the following exception:

Traceback (most recent call last):
  File "/Users/cwebster/.edm/envs/mayavi-38/lib/python3.8/site-packages/pyface/ui/qt4/console/console_widget.py", line 243, in eventFilter
    return self._event_filter_console_keypress(event)
  File "/Users/cwebster/.edm/envs/mayavi-38/lib/python3.8/site-packages/pyface/ui/qt4/python_shell.py", line 366, in _event_filter_console_keypress
    return super()._event_filter_console_keypress(event)
  File "/Users/cwebster/.edm/envs/mayavi-38/lib/python3.8/site-packages/pyface/ui/qt4/console/console_widget.py", line 1329, in _event_filter_console_keypress
    intercepted = not self._tab_pressed()
  File "/Users/cwebster/.edm/envs/mayavi-38/lib/python3.8/site-packages/pyface/ui/qt4/python_shell.py", line 338, in _tab_pressed
    self._complete()
  File "/Users/cwebster/.edm/envs/mayavi-38/lib/python3.8/site-packages/pyface/ui/qt4/python_shell.py", line 450, in _complete
    self._complete_with_items(cursor, completions)
  File "/Users/cwebster/.edm/envs/mayavi-38/lib/python3.8/site-packages/pyface/ui/qt4/console/console_widget.py", line 1025, in _complete_with_items
    self._page(self._format_as_columns(items))
  File "/Users/cwebster/.edm/envs/mayavi-38/lib/python3.8/site-packages/pyface/ui/qt4/console/console_widget.py", line 1514, in _format_as_columns
    char_width = QtGui.QFontMetrics(self.font).width(" ")
AttributeError: 'PySide6.QtGui.QFontMetrics' object has no attribute 'width'

See https://github.com/enthought/mayavi/pull/1158

Steps to Reproduce

Start Mayavi, enter from mayavi import mlab, type mlab. and then tab.

Probably simpler reproduction is possible.