If I have some painter, some rectangle and some string:
QPainter* pPainter;
//Initializing it
QRectF RectF;
//Initializing it
std::string strText = "Some string";
And I draw the rectangle with text using painter on some QGraphicsItem object and then we draw it on the scene:
pPainter->drawText(RectF, Qt::AlignCenter, strText);
Note: I cannot modify the code above, only to add something.
My goal is to get that text after a click on the rectangle. Suppose, that I've found mouseclick coordinates correctly.
Is there any way to get rectangle and its text using the coordinates of click? Or maybe I should hold some list of such rectangles to process them next? I've thought about use of itemAt() method, but I couldn't get rectangle that way.
std::string GetTextByCoordinates(int x, int y)
{
//What to do here?
}
Update: Method paint is used in class that inherited from QGraphicsItem (CustomItem), and there is several text rectangles on such items.
Method "GetTextByCoordinates" supposed to be called from that CustomItem object.