i have a scene with a multiple (QGraphicsTextItem)s, and i need to have control over their colors ,开发者_运维技巧 so how to change a color of a QGraphicsTextItem ? is it possible anyway? i've been trying for 3 days until now . please help
thanks in advanceI think you can change the text color by calling the method:
void QGraphicsTextItem::setDefaultTextColor ( const QColor & col );
You have an example here.
Or looking for Diagram Scene Example in your Qt Assistant.
setDefaultTextColor(col) "Sets the color for unformatted text to col." The documentation is not clear about what "unformatted text" means. I think it means: "all portions of the contents of the item that have not been styled."
The contents is a QTextDocument.
You style a part of a document using a QTextCursor. You can't style the QTextDocument per se, only a part that is selected by a QTextCursor (but you can select the whole document.)
You can style a QTextCursor using method mergeCharFormat(QTextCharFormat)
The QTextCharFormat has methods:
- foreground().setColor(QColor)
- setForeground(QBrush)
- setTextOutline(QPen)
Foreground is a QBrush that paints several things including "text" (but better said: the fill of characters?)
One nuance is that certain newly constructed QBrush have (default to) QBrushStyle.NoBrush, which is transparent, even if you setColor().
精彩评论