I want to draw a QGraphicsItem rectangle in QGraphicsScene / QGraphicsView framework, and inside the rectangle I want to draw some identifier text which is, say, 50%, of the size of the rectangle itself. I.e. the text size should scale to the rectangle size.
How can I do that?
I tried QFont::setPixelSize(size), but it does NOT work:
void
{
qreal width, height, size;
painter->drawRect(boundingRect());
width = widget->width();
height = widget->height();
if(height>=width) size = width; else size = height;
size /= 2;
monaco.setPixelSize((int)size);
pindex = "P("+pindex.setNum(patindex)+")";
painter->setFont(monaco);
painter->drawText(boundingRect(),Qt::AlignHCenter,pindex);
}
void
ChipItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
qreal width, height, size;
QFont monaco("Monaco");
QString pindex;
painter->drawRect(boundingRect());
width = widget->width();
height = widget->height();
if(height>=width) size = width; else size = height;
size /= 2;
monaco.setPixelSize((int)size);
pindex = "P("+pindex.setNum(patindex)+")";
painter->setFont(monaco);
painter->drawText(boundingRect(),Qt::AlignHCenter,pindex);
}
To copy to clipboard, switch view to plain text mode
Any suggestions?
Bookmarks