Repository: spyder-ide/spyder

Issue:
Keyboard shortcut dialog unuseable / crash
<!--- **PLEASE READ:** Before submitting here, please carefully consult our *Troubleshooting Guide*: https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ and search the issues page for your error/problem, as most posted bugs are duplicates or easy fixes.

If you don't find anything, please provide a detailed step-by-step description (in English) of the problem and what led up to it below. Issue reports without a clear way to reproduce them will be closed. Thanks! --->

## Problem Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

1. Open Keyboard shortcuts dialogue.

### What is the expected output?

I can edit keyboard shortcuts in the UI.

### What do you see instead?

Error dialogue pops up, cannot edit shortcuts. When I hide the error popup for the session, the editor is not functional either, with texts missing and graphical glitches.

I had a similar problem before, with #4146, when it was probably due to untested/incompatible qt version.



### Traceback
```python-traceback
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/spyder/widgets/helperwidgets.py", line 127, in paint
    textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
TypeError: subElementRect(self, QStyle.SubElement, QStyleOption, QWidget): not enough arguments
WARNING:spyder.widgets.github.backend:failed to send bug report on github. response={'code': 404, 'json': {'message': 'Not Found', 'documentation_url': 'https://developer.github.com/v3/issues/#create-an-issue'}}
```

## Package Versions

* Spyder version: 4.0.0.dev0 
* Python version: 3.6.5
* Qt version: 5.10.1
* PyQt5 version: 5.10.1
* Operating system: Linux 4.15.15-1-ARCH

### Dependencies

```
pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.4.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.22.0 (OK)
numpy >=1.7      :  1.14.2 (OK)
sphinx >=0.6.6   :  1.7.2 (OK)
rope >=0.9.4     :  0.10.6 (OK)
jedi >=0.11.0    :  0.11.1 (OK)
psutil >=0.3     :  5.4.5 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.28.2 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.3.1 (OK)
pylint >=0.25    :  1.8.4 (OK)
```



Discussion:
> Qt version: 5.10.1
PyQt5 version: 5.10.1

We don't support Qt/PyQt 5.10, so please downgrade to 5.9 until we fix this.
Downstream bug:
https://bugs.launchpad.net/ubuntu/+source/spyder/+bug/1832019

Steps to reproduce the bug in Ubuntu 18.04.3 LTS:
1. Install spyder3 and qt5-style-plugins (sudo apt install spyder3 qt5-style-plugins)
2. Run spyder3
3. Go to Tools → Preferences → General → Appearance
4. Change the Qt window style to cleanlooks, gtk2 or plastique
5. Go to Tools → Preferences → Keyboard shortcuts
6. Error (or crash in case of gtk2)

The Debian/Ubuntu maintainer of Qt and PyQt commented on the bug report and I quote it here in case it helps:

> It is a bug in Spyder, not in Qt:
> 
> 1) Cleanlooks and Plastique styles are inheriting from QProxyStyle.
> 2) So in Spyder’s HTMLDelegate.paint method, options.widget.style() returns a QProxyStyle.
> 3) In QProxyStyle.subElementRect method, the third argument is not optional, so should be specified: https://doc.qt.io/qt-5/qproxystyle.html#subElementRect
> 
> In C++, if the two-argument call is used, the compiler would ignore QProxyStyle::subElementRect and fall back to QCommonStyle::subElementRect. However, in Python there is no concept of overloading methods so this is not possible.
> 
> So Qt and PyQt behave according to their documentation.
> 
> Replacing style.subElementRect(QStyle.SE_ItemViewItemText, options) with style.subElementRect(QStyle.SE_ItemViewItemText, options, None) in Spyder code seems to help.
> 
> With regards to crash when using GTK2, it is a different and known issue. Qt uses GTK3 platformtheme (i.e. dialogs) by default, and it is incompatible with GTK2. If you want to use GTK2 then you should export QT_QPA_PLATFORMTHEME=gtk2. But I recommend against using GTK2 as it is deprecated.
Thanks for letting us know how to fix this. We'll do it for Spyder 4.
@steff456, please take care of this one. According to this comment:

> Replacing style.subElementRect(QStyle.SE_ItemViewItemText, options) with style.subElementRect(QStyle.SE_ItemViewItemText, options, None) in Spyder code seems to help.

You only need to search for the instances in our codebase that have this code:

    style.subElementRect(QStyle.SE_ItemViewItemText, options)

and add a `None` as the last argument of them.

Resolving patch:
diff --git a/spyder/plugins/findinfiles/widgets.py b/spyder/plugins/findinfiles/widgets.py
--- a/spyder/plugins/findinfiles/widgets.py
+++ b/spyder/plugins/findinfiles/widgets.py
@@ -734,7 +734,8 @@ def paint(self, painter, option, index):
 
         ctx = QAbstractTextDocumentLayout.PaintContext()
 
-        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
+        textRect = style.subElementRect(QStyle.SE_ItemViewItemText,
+                                        options, None)
         painter.save()
 
         painter.translate(textRect.topLeft())
diff --git a/spyder/widgets/helperwidgets.py b/spyder/widgets/helperwidgets.py
--- a/spyder/widgets/helperwidgets.py
+++ b/spyder/widgets/helperwidgets.py
@@ -130,7 +130,8 @@ def paint(self, painter, option, index):
 
         ctx = QAbstractTextDocumentLayout.PaintContext()
 
-        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
+        textRect = style.subElementRect(QStyle.SE_ItemViewItemText,
+                                        options, None)
         painter.save()
 
         # Adjustments for the file switcher
@@ -180,7 +181,8 @@ def paint(self, painter, option, index):
 
         ctx = QAbstractTextDocumentLayout.PaintContext()
 
-        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
+        textRect = style.subElementRect(QStyle.SE_ItemViewItemText,
+                                        options, None)
         painter.save()
 
         painter.translate(textRect.topLeft())


Test patch: