1

I've got a QGraphicsScene in which I added QPushButtons inside QGraphicsProxyWidgets. Is there a way to display tooltips for those buttons? The setToolTip works but nothing appear when I hover on the buttons. Do I need to specify some flag on the QGraphicsScene/View ?

A simplified version of the button creation code :

class Button(QPushButton):

def __init__(self, scene):

    super(Button, self).__init__()

    self.proxy = QGraphicsProxyWidget()
    self.proxy.setWidget(self)
    scene.addItem(self.proxy)

    self.setToolTip("tooltip")

Thanks in advance !

naide
  • 293
  • 3
  • 14
Loukana
  • 23
  • 6

2 Answers2

1

You have to set the tooltip to the QGraphicsProxyWidget.

Example:

from PyQt5 import QtCore, QtWidgets

if __name__ == '__main__':
    import sys

    app = QtWidgets.QApplication(sys.argv)
    scene = QtWidgets.QGraphicsScene()
    view = QtWidgets.QGraphicsView(scene)
    proxy = QtWidgets.QGraphicsProxyWidget()
    button = QtWidgets.QPushButton("Press me :)")
    proxy.setWidget(button)
    proxy.setToolTip("Proxy toolTip")
    scene.addItem(proxy)
    view.show()
    sys.exit(app.exec_())

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
0

Setting the tooltip on the proxy didn't work either, sadly, but a coworker looked a bit further in my code and found why neither proxy nor button's tooltip worked : I had set an override on the QGraphicsView mouseMoveEvent, which might have broken the hover event. Adding a...

else :
    super(CustomGraphicsView, self).mouseMoveEvent(event)

...at the end of the mouseMoveEvent override solved the problem. Sorry for the mistake, and thanks for the help !

Loukana
  • 23
  • 6