Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

qtpy exception (setResizeMode is only available in Qt4) #401

Closed
sergirubio opened this issue Feb 20, 2017 · 9 comments
Closed

qtpy exception (setResizeMode is only available in Qt4) #401

sergirubio opened this issue Feb 20, 2017 · 9 comments
Assignees
Labels
Milestone

Comments

@sergirubio
Copy link

It seems that a deprecated Qt4 method is called:

File "/home/sicilia/src/taurus/lib/taurus/qt/qtgui/table/taurusdevicepropertytable.py", line 186, in updateStyle
QtGui.QHeaderView.ResizeToContents) # .Stretch)
File "/usr/lib/python2.7/dist-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.

@sergirubio
Copy link
Author

Same error on TaurusValuesTable

Traceback (most recent call last):
File "/home/sicilia/src/taurus/lib/taurus/qt/qtgui/base/taurusbase.py", line 319, in filterEvent
self.handleEvent(*evt)
File "/home/sicilia/src/taurus/lib/taurus/qt/qtgui/table/taurusvaluestable.py", line 726, in handleEvent
hh.setResizeMode(Qt.QHeaderView.Fixed)
File "/usr/lib/python2.7/dist-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.

@cpascual
Copy link
Member

This is strange...
I was not aware that we are (yet) be using qtpy in Taurus (maybe I forgot?).

Taurus should be only using PyQt4 for now... I wonder if there is something unusual in your installation?

That said, it is interesting to note these kind of warnings since we are eventually going to have to deal with them.

@cpascual
Copy link
Member

cpascual commented Mar 31, 2017

Note:" the same exception can be triggered on a debian9 by e.g.,

taurusform sys/tg_test/1/boolean_spectrum

... but it does not happen if using python -m taurus.qt.qtgui.table.taurusvaluestable

(so I assume that qtpy is being loaded when using taurusform)

Also note that the suggestion to use setSectionResizeMode does not work when qtpy is not imported, since setSectionResizeMode is not present in Qt4

@cpascual
Copy link
Member

Can anybody help in reproducing the problem (of loading qtpy) with an small snippet?

@cpascual cpascual added this to the Jul17 milestone Jun 13, 2017
@cpascual cpascual self-assigned this Jun 14, 2017
@cpascual cpascual changed the title Exception in TaurusDevicePropertyTable.updateStyle() qtpy exception (setResizeMode is only available in Qt4) Jun 16, 2017
@cpascual
Copy link
Member

cpascual commented Jun 16, 2017

Here is a smaller snippet for reproducing the exception.
(it seems that importing the taurus.qt.qtgui.editor module triggers the issue)

from taurus.external.qt import Qt
from taurus.qt.qtgui.application import TaurusApplication
app = TaurusApplication()

# Commenting this import makes the exception disappear
from taurus.qt.qtgui.editor import TaurusBaseEditor

Qt.QHeaderView(Qt.Qt.Vertical).setResizeMode(Qt.QHeaderView.Fixed)

Running it one gets:

Traceback (most recent call last):
  File "/home/cpascual/src/tests/taurus/bug401.py", line 9, in <module>
    Qt.QHeaderView(Qt.Qt.Vertical).setResizeMode(Qt.QHeaderView.Fixed)
  File "/usr/lib/python2.7/dist-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.

@cpascual
Copy link
Member

It looks like this is a bug introduced by qtpy.
qtpy has side effects even when you do not import it directly:
spyder-ide/qtpy#65 (comment)

@cpascual
Copy link
Member

cpascual commented Jun 16, 2017

I created an issue in qtpy:
spyder-ide/qtpy#119

@cpascual
Copy link
Member

As a workaround in the meanwhile we could do the ugly thing of trying setSectionResizeMode before defaulting to setResizeMode (note that we have to try both because we cannot predict whether the user has already imported qtpy or not when we want to do the resize).

Or, alternatively, we could do an early import of qtpy in taurus.qt to make sure that the intrusive patching is done (note that this is just pushing the same problem towards taurus users, whose code could be broken)

cpascual pushed a commit to cpascual/taurus that referenced this issue Jun 20, 2017
Force an early import of qtpy and use pyqt5 API for QHeaderView in
order to work around bug taurus-org#401

See also spyder-ide/qtpy#119

Fixes taurus-org#401
@cpascual
Copy link
Member

I finally opted for the "early import" workaround. See #473

reszelaz added a commit that referenced this issue Jul 4, 2017
(Fix #401) Work-around bug introduced by qtpy
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants