{
Q_OBJECT
public:
virtual QSize sizeHint
() const{return szHint;
} virtual QSize minimumSizeHint
() const{return minSzHint;
} private:
};
{
minSzHint
= QSize(10,
10);
adjustSize ();
m_text = text;
}
QRectF GraphicsTextItem
::boundingRect() const {
qreal penWidth = 1;
return QRectF(4 - penWidth
/ 2,
0 - penWidth
/ 2,
30 + penWidth / 2, PIN_HEIGHT + penWidth / 2);
}
{
painter->drawRect(boundingRect());
painter->drawText(boundingRect(),Qt::AlignCenter,m_text.left(5));
}
class GraphicsTextItem : public QGraphicsTextItem
{
Q_OBJECT
public:
GraphicsTextItem(const QString & text, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 );
virtual QSize sizeHint() const{return szHint;}
virtual QSize minimumSizeHint() const{return minSzHint;}
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
QSize szHint, minSzHint;
QString m_text;
};
GraphicsTextItem::GraphicsTextItem(const QString & text, QGraphicsItem * parent , QGraphicsScene * scene )
:QGraphicsTextItem( text,parent,scene )
{
szHint = QSize(10,10);
minSzHint = QSize(10, 10);
adjustSize ();
m_text = text;
}
QRectF GraphicsTextItem::boundingRect() const
{
qreal penWidth = 1;
return QRectF(4 - penWidth / 2, 0 - penWidth / 2,
30 + penWidth / 2, PIN_HEIGHT + penWidth / 2);
}
void GraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
painter->drawRect(boundingRect());
painter->drawText(boundingRect(),Qt::AlignCenter,m_text.left(5));
}
To copy to clipboard, switch view to plain text mode
Bookmarks