Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QHeaderView.setSectionResize for Qt4 layer #70

Closed
mottosso opened this issue Aug 27, 2016 · 2 comments
Closed

Add QHeaderView.setSectionResize for Qt4 layer #70

mottosso opened this issue Aug 27, 2016 · 2 comments

Comments

@mottosso
Copy link

Hi qtpy,

As discussed in #65, I've got a problem, and it occurs at random.

Reproducible

# Ubuntu 16.04
$ apt-get update
$ apt-get install python3-pyside git
$ git clone https://github.com/spyder-ide/qtpy.git
$ export PYTHONPATH=$(pwd)/qtpy
$ python3
>>> from PySide import QtGui
>>> # setSectionResizeMode is added by qtpy on import
>>> assert not hasattr(QtGui.QHeaderView, "setSectionResizeMode")
>>> import sys
>>> from qtpy import QtWidgets
>>> app = QtWidgets.QApplication(sys.argv)
>>> widget = QtWidgets.QTreeView()
>>> qheaderview = widget.header()
>>> qheaderview.setSectionResizeMode(qheaderview.Fixed)
AttributeError: 'PySide.QtGui.QHeaderView' object has no attribute 'setSectionResizeMode'

The error there is thrown 9/10 times I try. :(

If I remove the line with hasattr, it works 10/10, so I figure some magic (threaded initialisation?) must be occurring on this line.

@goanpeca goanpeca changed the title QHeaderView.setSectionResize on Python 3 works randomly Add QHeaderView.setSectionResize for Qt4 layer Dec 29, 2016
@goanpeca goanpeca added this to the v1.2 milestone Dec 29, 2016
@goanpeca
Copy link
Member

goanpeca commented Dec 29, 2016

@mottosso maybe we need to override the QTreeView, QTableView classes so that the __init__ method adds the patched QHeaderView.

class QTableView(OriginalQtTableView):
    def __init__(self, *args, **kwargs):
        super(QTableView, self).__init__(*args, **kwargs)
        self.setHorizontalHeader(QHeaderView(self))
        self.setVerticalHeader(QHeaderView(self))

But if we are doing this, I would rather not use patches, but override classes as needed.

@mottosso
Copy link
Author

mottosso commented Jan 1, 2017

Possibly.

The trouble I've found with replacing classes with subclasses, as opposed to monkey patching, is that Qt is still returning the original classes from calls such as .parent() from another widget. It might not be a problem in most cases, but is a little inconsistent and perhaps unexpected at times.

@ccordoba12 ccordoba12 modified the milestones: v1.2, v1.3 Jan 2, 2017
@ccordoba12 ccordoba12 modified the milestones: v1.3, v1.4 May 8, 2017
@ccordoba12 ccordoba12 modified the milestones: v1.4, v1.5 Mar 11, 2018
@ccordoba12 ccordoba12 removed this from the v1.5 milestone Aug 25, 2018
@goanpeca goanpeca removed their assignment Aug 22, 2020
jschueller added a commit to jschueller/qtpy that referenced this issue Oct 12, 2021
jschueller added a commit to jschueller/qtpy that referenced this issue Oct 13, 2021
jschueller added a commit to jschueller/qtpy that referenced this issue Oct 13, 2021
@ccordoba12 ccordoba12 added this to the v2.0.0 milestone Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants