Search code examples
pythonpython-2.7qtpysidemaya

Setting the cursor for a header in a QTreeWidget via PySide


I'm trying to set the cursor for a QTreeWidget's header for when the user hovers over the header. I have tried setting the header in the class through self.header().setCursor( my_cursor ), but so far the cursor isn't changing when I hover my mouse over the header. I've searched through Google to try to track down how to do this, but so far I have found nothing. I have tested with PySide 1.2.0 (in Maya 2015) and 1.2.2.

Am I doing this wrong, or is there a workaround? Here's some example of code:

import sys
from PySide import QtCore, QtGui

class Tree( QtGui.QTreeWidget ):

    def __init__(self, parent = None):
        super(Tree, self).__init__(parent = parent)
        self.header().setCursor(QtGui.QCursor( QtCore.Qt.WaitCursor))

widget = Tree()
widget.show()

If I set the cursor on the tree widget itself, then the cursor is set as expected.


Solution

  • There is no need to reset the header of the tree.

    Just set the cursor on the viewport of the existing header:

        self.header().viewport().setCursor(QtCore.Qt.WaitCursor)