How to change the color of a QGraphicsTextItem

I have a scene with several (QGraphicsTextItem) s and I need to control their colors, so how do I change the color of QGraphicsTextItem? is this possible anyway? I have tried for 3 days so far. please, help


thanks in advance

+7
python qt qt4 pyqt
source share
2 answers

I think you can change the color of the text by calling the method:

void QGraphicsTextItem::setDefaultTextColor ( const QColor & col );

You have an example here .

Or look for an example chart scene in your Qt helper.

+6
source share

setDefaultTextColor (col) "Sets the color for unformatted text in col." The documentation is not clear what “unformatted text” means. I think this means: "all parts of the contents of the subject that were not written."

Content is a QTextDocument.

You create part of the document using QTextCursor. You cannot style QTextDocument as such, but only the part selected by QTextCursor (but you can select the entire document.)

You can create a QTextCursor using the mergeCharFormat (QTextCharFormat) method

QTextCharFormat has methods:

  • foreground (). setColor (QColor)
  • setForeground (QBrush)
  • setTextOutline (QPen)

Foreground is a QBrush that draws a few things, including “text” (but better said: padding characters?)

One caveat is that some recently built QBrush have (by default) QBrushStyle.NoBrush, which is transparent even if you set Color ().

+1
source share

All Articles