[Solved] Adding text inside QGraphicsEllipseItem
-
Hi All,
I have the following code which is generating 5 ellipses in a horizontal line :
@
void Widget::createItem( int x, QGraphicsScene *scene )
{
QRect rect(x+105, 50, 145, 100);
ellipseItem = new QGraphicsEllipseItem( rect, 0, scene );QBrush brush; QPixmap pix(250,250); pix.fill(Qt::transparent); QPainter paint(&pix); paint.setPen("black"); paint.setOpacity(0.75); paint.drawText(rect, Qt::AlignCenter ,"OK"); brush.setTexture(pix); ellipseItem->setBrush(brush);
}
@Values of x = 0, 200, 400, 600, 800
For the above code, the first instance works perfect i.e. "OK" is displayed in the center of the 1st QGraphicsEllipseItem but not for the others....what am i doing wrong?
Please help.
-
Not sure what you are trying to accomplish, but if you want to create a graphics item that is displayed as an ellipse with text in it, this it definitely not the way to do it.
You have to make that graphics item draw the text as well, you cannot just do that yourself when you create the item. To do that, you could subclass QGraphicsEllipseItem, reimplement the paint event, and paint the text in there (before or after you call the QGraphicsEllipseItem paint event).