I was able to put a "label" on a QGraphicPixmapItem by doing the following:
{
public
private:
};
class DeviceItem: public QGraphicsPixmapItem
{
public
DeviceItem(DevData* data, QMenu *contextMenu, QGraphicsItem *parent = 0);
private:
QGraphicsSimpleTextItem* m_pText;
};
To copy to clipboard, switch view to plain text mode
and
{
QRect rect
= this
->pixmap
().
rect();
QRectF rectF
= m_pText
->boundingRect
();
int x = (rect.width()/2) - (rectF.width()/2);
m_pText->setPos(x, rect.bottom());
}
DeviceItem::DeviceItem(DevData* data, QMenu* contextMenu, QGraphicsItem* parent) :
QGraphicsPixmapItem(QPixmap(data->getIcon()), parent), m_pText(NULL), m_Menu(contextMenu)
{
setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
m_pText = new QGraphicsSimpleTextItem(data->getName(), this);
QRect rect = this->pixmap().rect();
QRectF rectF = m_pText->boundingRect();
int x = (rect.width()/2) - (rectF.width()/2);
m_pText->setPos(x, rect.bottom());
}
To copy to clipboard, switch view to plain text mode
This puts the "label" centered underneath the pixmap. (As for arrow, that's the code to keep the items connected by the lines)
Vycke
Bookmarks