Pass Size and Text to a QGraphicsItem
I have subclassed QGraphicsItem to draw a roundedRect with two lines of text in.
I would like to pass the size and the text to the item so the item can be used dynamically for a number of different items.
the code i have is below:
Code:
{
public:
//SimpleItem(QString Title);
{
qreal penWidth = 1;
return QRectF(-10 - penWidth
/ 2,
-10 - penWidth
/ 2,
20 + penWidth, 20 + penWidth);
}
{
painter->drawRoundedRect(-10, -10, 100, 50, 5, 5);
//painter->brush(Qt::blue);
//QVariant title = title;
painter->drawText(10, 10, "Title");
painter->drawText(10, 30, "Subtitle");
}
};
Re: Pass Size and Text to a QGraphicsItem
What's the problem? Add a function to set the parameters and trigger an update(); provide a constuctor that takes the parameters as arguments and calls the previous function. Straight-up C++.