开发者

how to change the color of a QGraphicsTextItem

开发者 https://www.devze.com 2023-01-10 04:14 出处:网络
i have a scene with a multiple (QGraphicsTextItem)s, andi need to have control over their colors ,开发者_运维技巧 so how to change a color of a QGraphicsTextItem ? is it possible anyway? i\'ve been tr

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 advance


I 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().

0

精彩评论

暂无评论...
验证码 换一张
取 消