How to write text to the screen
I wanted to write the score in a game of pong. So I wanted the string “Score: “ printed centered at the top and bottom of the screen, followed by the integer corresponding to the player’s score. How would I do this?
Can you add a bit of context, please? Are you doing custom drawing for your widgets or what?
The way I wanted to be able to do it was to basically have a text object that I could manipulate the same way I would, say, a rectangle object or an ellipse object. Basically something that I could easily resize and move around. Does that help at all?
That seems to work, but now I have another issue. If I change what’s in the item, by using setPlainText(QString), it doesn’t remove what was already on the screen. It just adds it at the end of what was already there (I only call addItem(QGraphicsTextItem) once). How would I make it update?