{
Q_OBJECT
public:
enum { Type = UserType + 3 };
void setBoundingRect( qreal x, qreal y, qreal w, qreal h);
void setText
( const QString &inText
);
signals:
protected:
private:
};
class DiagramTextItem : public QGraphicsTextItem
{
Q_OBJECT
public:
enum { Type = UserType + 3 };
DiagramTextItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
void setBoundingRect( qreal x, qreal y, qreal w, qreal h);
void setText( const QString &inText );
signals:
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
QRectF boundingRect() const;
private:
QRectF myBoundRect;
QTextOption textOp;
QString text;
};
To copy to clipboard, switch view to plain text mode
{
myBoundRect.setRect( 0, 0, 0, 0 );
textOp.setAlignment( Qt::AlignCenter );
textOp.
setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
}
{
//painter->drawRect( boundingRect() );
painter->drawText( boundingRect(),
text,
textOp);
}
QRectF DiagramTextItem
::boundingRect() const {
return myBoundRect;
}
void DiagramTextItem::setBoundingRect( qreal x, qreal y, qreal w, qreal h)
{
myBoundRect.setRect( x, y, w, h );
}
void DiagramTextItem
::setText( const QString &inText
) {
text = inText;
update();
}
DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, QGraphicsScene *scene)
: QGraphicsTextItem(parent, scene)
{
myBoundRect.setRect( 0, 0, 0, 0 );
textOp.setAlignment( Qt::AlignCenter );
textOp.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
}
void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *widget)
{
//painter->drawRect( boundingRect() );
painter->drawText( boundingRect(),
text,
textOp);
QGraphicsTextItem::paint(painter, option, widget);
}
QRectF DiagramTextItem::boundingRect() const
{
return myBoundRect;
}
void DiagramTextItem::setBoundingRect( qreal x, qreal y, qreal w, qreal h)
{
myBoundRect.setRect( x, y, w, h );
}
void DiagramTextItem::setText( const QString &inText )
{
text = inText;
update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks