but how to obtain a text centered both vetically and horizontally in the rectangle?
thats what i am suggesting .. combine both the text and rectangle into single QGraphicsItem ..
paint such that
create a custom QGraphicsItem()
{
Q_OBJECT
public:
CustomItem
(const QRectF &rect
);
};
class CustomItem : public QGraphicsRectItem
{
Q_OBJECT
public:
CustomItem(const QRectF &rect);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
QRectF boundingRect();
};
To copy to clipboard, switch view to plain text mode
CustomItem
::CustomItem(const QRectF &rect
){
textItem
->setDefaultTextColor
(QColor(255,
255,
255,
255));
textItem->setPos(x, y); //here u set position of text
textItem->setPlainText(message); //set your text here
}
{
painter->drawRect(rect());
}
CustomItem::CustomItem(const QRectF &rect)
: QGraphicsRectItem(rect)
{
textItem->setDefaultTextColor(QColor(255,255,255,255));
textItem->setPos(x, y); //here u set position of text
textItem->setPlainText(message); //set your text here
}
void CustomItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *widget)
{
painter->setBrush(QBrush(QColor(21, 155, 210, 255)));
painter->drawRect(rect());
}
To copy to clipboard, switch view to plain text mode
now the item is ready in horizontal ... now in parent graphicsView() rotate it using previous code ...
Bookmarks