2011-12-10 25 views
1

我一直在寻找像QGraphicsTextItem::setPen()或甚至QFont::setColor()QFont::setForegroundColor()的选项。它们都不存在。如何在QGraphicsScene上绘制彩色文字?

如何在QGraphicsScene上绘制彩色文字?我不想使用QGraphicsTextItem::setHtml()并使用HTML来做到这一点(不知道如果这是可能的,但)。

我使用的是Qt 4.7.4。

回答

1

QGraphicsTextItem有一个palette方法返回一个QPaletteQPalette有setColor方法,它需要一个角色。

void QPalette::setColor (ColorRole role, const QColor & color) 

The role you want is 

QPalette::Text The foreground color used with Base. 
This is usually the same as the WindowText, in which case it must provide 
good contrast with Window and Base. 
+0

我找不到'QGraphicsTextItem ::调色板()'。 – Donotalo

2
scene.addText(tr("Hello World"))->setDefaultTextColor(Qt::white);