1 Attachment(s)
QGraphicsRectItem with text
I subclass QGraphicsRectItem in order to add a text inside the rectangle.
1) The text doesn't get re-paint properly. When I created it as
Code:
RectItem *myRect = new JFIRectItem("A Very Long Long Word");
addItem(myRect);
it shows up on the QGraphicsScene fine, but the text is missing when I have it in a dropEvent
Code:
RectItem *item = new RectItem(m_selectedJFIName.c_str());
item->setPos(mouseEvent->scenePos());
addItem(item);
2) How am I going to wrap the text so that it will fit inside the rectangle and to also re-size the rectangle as needed
Attachment 3609
Code:
{
Q_OBJECT
public:
private:
std::string m_text;
};
{
m_text = text;
}
{
painter->drawText(pos, m_text.c_str());
painter
->setPen
(QPen(Qt
::black,
1));
painter->drawRoundRect(rect());
}
Thanks.
Re: QGraphicsRectItem with text
You have to deal with QTextDocument, but it might be easier to subclass QGraphicsTextItem and draw the border...