Hi there,

I am currently implementing a TextFrame QGI, that will typically look
like a sticky note.
I want the user to be able to control the size of the frame, so I
decided to implement my frame class as a direct subclass of QGI and use
composition to manage the text through a QGraphicsTextItem.
I'm doing pretty well except for one thing: since the height of the QGTI
cannot be controlled I set the ItemClipsChildrenToShape flag on my frame
class (the parent item), thinking it will hide any text of the QGTI (the
child item) that doesn't overlap the shape of my frame.

According to the documentation this is exactly what the flag is intended
for, but nfortunaately it doesn't work in my case, whatever the shape of
my parent item, the text always renders from the top to the bottom.

This is what my constructor looks like:
GraphicsTextFrameItem::GraphicsTextFrameItem(SchItem *parent):
SchItem(parent),
m_textItem(new QGraphicsTextItem(this))
{
m_textItem->setPos(0, 0);
connect(m_textItem, &QGraphicsTextItem::linkActivated,
this, &GraphicsTextFrameItem::linkActivated);
connect(m_textItem, &QGraphicsTextItem::linkHovered,
this, &GraphicsTextFrameItem::linkHovered);

setFlag(QGraphicsItem::ItemClipsChildrenToShape);
}

And here is how I manage resizing:
void GraphicsTextFrameItem::itemNotification(IGraphicsObservableItem *item)
{
AbstractGraphicsHandle *handle =
dynamic_cast<AbstractGraphicsHandle*>(item);
Q_ASSERT(handle && handle->handleId() == 0);

prepareGeometryChange();
m_frameRect.setBottomRight(handle->pos());
m_textItem->setTextWidth(m_frameRect.width());
m_boundingRect = QRectF();
update();
}

The graphics handle is a small item class that sends notification when
it is moved around, typically used a control point and size handler.

It looks like I'm missing something, or maybe I just misunderstood the
documentation. Any help or point out appreciated.

Thanks,
Chris


_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to