c++ - How to place QGraphicsSimpleTextItem in the middle of a QGraphicsLineItem? -


I inherited the kgfixicsline itam for a new class, whose name is linepointline. When I create a point line in every way, I have to put some text in the center of the line:

  // Draw Line Setline (localPoint1.X (), localPoint1.Y (), LocalPoint 2.x (), Local Point 2.Y ()); // Set the parent item for the text, so it can be appropriately deleted later .setParentItem (this); Text.setPos ((localPoint1.X () + localPoint2.X ()) / 2, (localPoint1.Y () + localPoint2.Y ()) / 2); Text.setText ("some");  

However, the text does not appear in the middle of the line ... How can I fix this?

I think that when you set the text as a child of the line, its The coordinates should be relative to it. You will do something like

  text.setPos ((width ()) / 2,0);  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -