How to draw colored text on QGraphicsScene?

前端 未结 3 949
渐次进展
渐次进展 2021-01-14 05:35

I was looking for options like QGraphicsTextItem::setPen(), or even QFont::setColor() or QFont::setForegroundColor(). None of them exi

相关标签:
3条回答
  • 2021-01-14 06:16

    Are you looking for a combination of setPlainText() and setDefaultTextColor()?

    http://doc.qt.io/archives/qt-4.7/qgraphicstextitem.html#setPlainText

    http://doc.qt.io/archives/qt-4.7/qgraphicstextitem.html#setDefaultTextColor

    If not, I'm not sure I understand your question...

    0 讨论(0)
  • 2021-01-14 06:27
    scene.addText(tr("Hello World"))->setDefaultTextColor(Qt::white);
    
    0 讨论(0)
  • 2021-01-14 06:30

    QGraphicsTextItem has a palette method which returns a QPalette and QPalette has the setColor method which takes a role.

    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 讨论(0)
提交回复
热议问题