Omer
Omer

Reputation: 456

PyQt4: Add text to QGraphicsView (not the scene)

I want to add a text to a QGraphicsView, but not to the scene. That's because I want the text to stay in a fixed position in relation to the QGraphicsView. I don't want it to move when scrolling through the scene.

There is no "addText" method for QGraphicsView, so what can I do?

edit: I think what I want is a transparent widget on top of the graphics view and to draw on it. How do I place one widget on top of another?

Upvotes: 0

Views: 989

Answers (1)

Omer
Omer

Reputation: 456

Eventually my solution was to add a parent QLabel to the QGraphicsView. The QLabel has transparent background color, and only text is shown. It is important to apply: label.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents) so that it won't interfere with mouse events of the QGraphicsView.

Also, it cannot be done using the Qt Designer, or at least I haven't figured out a way to add widgets with a parent.

Upvotes: 1

Related Questions