如何在QGraphicsScene上绘制彩色文本?

3
我正在寻找像QGraphicsTextItem::setPen(),甚至是QFont::setColor()QFont::setForegroundColor()这样的选项,但它们都不存在。
我怎样才能在QGraphicsScene上绘制带颜色的文本?我不想使用QGraphicsTextItem::setHtml()和HTML来实现(虽然不确定是否可能)。
我正在使用Qt 4.7.4。
3个回答

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

3

1

QGraphicsTextItem有一个palette方法,它返回一个QPalette,而QPalette具有设置颜色的方法,该方法需要一个角色。

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.

我找不到 QGraphicsTextItem::palette() - Donotalo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接