QPainter how to draw text with different colors?



  • Hi,
    how could I draw text with different colors for e.g.

    "One Two" where One is yellow and Two is red ?

    BR,
    Tomek



  • You can use this:

    QPainter painter(this);
    painter.setPen(Qt::yellow);
    painter.drawText(0, 20, "One");
    painter.setPen(Qt::red);
    painter.drawText(QFontMetrics(painter.font()).size(Qt::TextSingleLine, "One ").width(), 20, "Two");
    

    but maybe there are better solutions :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.