PDA

View Full Version : Pass Size and Text to a QGraphicsItem



dubstar_04
11th April 2011, 21:31
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:



class SimpleItem : public QGraphicsItem
{
public:

//SimpleItem(QString Title);

QRectF boundingRect() const
{
qreal penWidth = 1;
return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
20 + penWidth, 20 + penWidth);
}

void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
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");
}
};

SixDegrees
12th April 2011, 07:44
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++.