質問

i am adding a qgraphicsTextitem when the user clicks on the graphicsview and i will set the edit mode for the graphicstextitem using setTextInteractionFlags(Qt::TextEditorInteraction);

but the problem is the user can edit the text and the text is exceeding the viewport visible area or the scene rect.

the text the user entered should restrict inside the sceneRect , how i can do it in graphics framework.

also when the textitem text starts in middle and the entered text exits the sceneRect i have to shift the text pos left side.

役に立ちましたか?

解決

You have to explicitly set the sceneRect of the QGraphicsScene. Otherwise, it will grow automatically. You will want it to be fixed size.

Then, you need to subclass QGraphicsTextItem, or create your own QGraphicsItem from scratch.

Maybe if you override virtual QRectF boundingRect () const, you could call the base boundingRect, do a check if it's outside the scene rect, and move the item to the left with setPos.

Remember that the bounding rect is in item coordinates, you need to consider the item position to get the scene coordinates.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top