If you want to have a centered string inside a QGraphicsTextItem you can use this simple workaround
:
Suppose that m_gtextItem is your QGraphicsTextItem.
To change the alignment and obtaining an AlignHCenter one you should write
a method like this:
void setTextAlignment(Qt::Alignment alignment)
{
bfmt.setAlignment(Qt::AlignCenter);
cursor.setBlockFormat(bfmt);
m_gtextItem->setTextCursor(cursor);
}
void setTextAlignment(Qt::Alignment alignment)
{
QTextCursor cursor = m_gtextItem->textCursor();
QTextBlockFormat bfmt = cursor.blockFormat();
bfmt.setAlignment(Qt::AlignCenter);
cursor.setBlockFormat(bfmt);
m_gtextItem->setTextCursor(cursor);
}
To copy to clipboard, switch view to plain text mode
This method change the alignment of the QTextBlockFormat of the current cursor position (that would be a selection, or, if you want the entire document).
Bye bye,
Angelo
Bookmarks