pythonpyqttooltipqgraphicsview

Qt QGraphicsView - tooltips don't appear


I'm creating a 2D view in PyQt using the QGraphicsView. Unfortunately, I can't seem to find any way of getting tooltips to appear at any level - on QGraphicsItems, QGraphicsItemGroups, etc.

It's getting to the point where they'd be very useful, but I have tried:

  1. Setting the tooltips using setToolTip().
  2. Using setAttribute(QtCore.Qt.WA_AlwaysShowToolTips) on the QGraphicsView

The second I thought would be a dead-cert, but appears to do nothing at all...


Solution

  • This seems to work as expected using python Qt 4.8.7 with PyQt 4.11.4:

    from PyQt4 import QtGui
    
    class Window(QtGui.QWidget):
        def __init__(self):
            super(Window, self).__init__()
            self.view = QtGui.QGraphicsView(self)
            self.view.setScene(QtGui.QGraphicsScene(self))
            for index, name in enumerate('One Two Three Four Five'.split()):
                item = QtGui.QGraphicsRectItem(index * 60, index * 60, 50, 50)
                item.setToolTip('Rectangle: ' + name)
                self.view.scene().addItem(item)
            layout = QtGui.QVBoxLayout(self)
            layout.addWidget(self.view)
    
    if __name__ == '__main__':
    
        import sys
        app = QtGui.QApplication(sys.argv)
        window = Window()
        window.resize(400, 400)
        window.show()
        sys.exit(app.exec_())
    

    Presumably, there must be something different in your own code that is compromising the normal behaviour. But that will be impossible to identify without a proper test case.