Repository: spyder-ide/spyder

Issue:
Qtpy 1.2.0 breaks Spyder with Qt4
## Description of your problem

Spyder crashes if I upgrade qtpy from 1.1.2 to 1.2.0

Originally I posted in the spyder-ide repository, but I was redirected here.
https://github.com/spyder-ide/qtpy/issues/95

**What steps will reproduce the problem?**

1. pip install -U qtpy (installs version 1.2.0 and breaks Spyder)
2. pip install qtpy==1.1.2 (everything working again) 

**What is the expected output? What do you see instead?**

Spyder doesn't start correctly, showing the following message:

```python-traceback
File "/home/developer/.virtualenvs/dev3/lib/python3.5/site-packages/spyder/app/mainwindow.py", line 3001, in main
mainwindow = run_spyder(app, options, args)
File "/home/developer/.virtualenvs/dev3/lib/python3.5/site-packages/spyder/app/mainwindow.py", line 2905, in run_spyder
main.setup()
File "/home/developer/.virtualenvs/dev3/lib/python3.5/site-packages/spyder/app/mainwindow.py", line 869, in setup
self.projects = Projects(self)
File "/home/developer/.virtualenvs/dev3/lib/python3.5/site-packages/spyder/plugins/projects.py", line 71, in init
self.setup_project(self.get_active_project_path())
File "/home/developer/.virtualenvs/dev3/lib/python3.5/site-packages/spyder/widgets/projects/explorer.py", line 226, in setup_project
show_all=self.show_all)
File "/home/developer/.virtualenvs/dev3/lib/python3.5/site-packages/spyder/widgets/explorer.py", line 195, in setup
self.common_actions = self.setup_common_actions()
File "/home/developer/.virtualenvs/dev3/lib/python3.5/site-packages/spyder/widgets/projects/explorer.py", line 55, in setup_common_actions
self.toggle_hscrollbar(self.show_hscrollbar)
File "/home/developer/.virtualenvs/dev3/lib/python3.5/site-packages/spyder/widgets/projects/explorer.py", line 70, in toggle_hscrollbar
self.header().setResizeMode(QHeaderView.ResizeToContents)
File "/home/developer/.virtualenvs/dev3/lib/python3.5/site-packages/qtpy/_patch/qheaderview.py", line 83, in setResizeMode
raise Exception('setResizeMode is only available in Qt4. Use '
Exception: setResizeMode is only available in Qt4. Use setSectionResizeMode instead.
```

## Versions and main components

* Spyder Version: 3.0.2
* Python Version: 3.5.2
* Operating system: Ubuntu 16.04
* Qt4 related info: Qt 4.8.7, PyQt 4.11.4, SIP 4.18.1

## Dependencies
jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.5.3 (OK)
nbconvert >=4.0  :  4.2.0 (OK)
numpy >=1.7      :  1.11.2 (OK)
pandas >=0.13.1  :  0.19.1 (OK)
pep8 >=0.6       :  1.7.0 (OK)
psutil >=0.3     :  5.0.0 (OK)
pyflakes >=0.6.0 :  1.3.0 (OK)
pygments >=2.0   :  2.1.3 (OK)
pylint >=0.25    :  1.6.4 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
sphinx >=0.6.6   :  1.4.8 (OK)
sympy >=0.7.3    :  1.0 (OK)





Discussion:
@rlaverde could you work on this one?
We need this for today or tomorrow morning at most @rlaverde :-)

Resolving patch:
diff --git a/spyder/widgets/projects/explorer.py b/spyder/widgets/projects/explorer.py
--- a/spyder/widgets/projects/explorer.py
+++ b/spyder/widgets/projects/explorer.py
@@ -15,7 +15,6 @@
 import shutil
 
 # Third party imports
-from qtpy import PYQT5
 from qtpy.QtCore import Qt, Signal, Slot
 from qtpy.QtWidgets import (QAbstractItemView, QHBoxLayout, QHeaderView,
                             QLabel, QMessageBox, QVBoxLayout, QWidget)
@@ -64,9 +63,9 @@ def toggle_hscrollbar(self, checked):
         self.show_hscrollbar = checked
         self.header().setStretchLastSection(not checked)
         self.header().setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
-        if PYQT5:
+        try:
             self.header().setSectionResizeMode(QHeaderView.ResizeToContents)
-        else:
+        except:  # support for qtpy<1.2.0
             self.header().setResizeMode(QHeaderView.ResizeToContents)
 
     #---- Internal drag & drop
diff --git a/spyder/widgets/variableexplorer/dataframeeditor.py b/spyder/widgets/variableexplorer/dataframeeditor.py
--- a/spyder/widgets/variableexplorer/dataframeeditor.py
+++ b/spyder/widgets/variableexplorer/dataframeeditor.py
@@ -15,7 +15,7 @@
 
 # Third party imports
 from pandas import DataFrame, DatetimeIndex, Series
-from qtpy import API, PYQT5
+from qtpy import API
 from qtpy.compat import from_qvariant, to_qvariant
 from qtpy.QtCore import QAbstractTableModel, QModelIndex, Qt, Signal, Slot
 from qtpy.QtGui import QColor, QCursor
@@ -426,9 +426,9 @@ def __init__(self, parent):
         self.setModel(parent.model())
         self.setFocusPolicy(Qt.NoFocus)
         self.verticalHeader().hide()
-        if PYQT5:
+        try:
             self.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed)
-        else:
+        except:  # support for qtpy<1.2.0
             self.horizontalHeader().setResizeMode(QHeaderView.Fixed)
 
         parent.viewport().stackUnder(self)


Test patch: