[SOLVED] Text with outline pen failure

  • I cannot get some simple text to paint with an outline. I wanted red text with a black outline. So I did this:

    Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog)
    scene = new QGraphicsScene(this);

    QBrush redbrush(Qt::red);
    QPen   blackpen(Qt::black);
    QFont font;
    font.setFamily("Times New Roman");
    txt = new QGraphicsSimpleTextItem();


    I get red text as I had wanted, but it does not have a black outline. What else must I do to make this work? If I change the color of the brush, the text will change color appropriately but I cannot get the QPen to paint its border into the scene. Any help would be appreciated. Must I override paint() for this class?

  • Moderators

    You can try QGraphicsPathItem instead of QGraphicsSimpleTextItem. Create QPainterPath, use addText() on it and setPath() on the item.

  • Krzysztof,

    That works perfectly. Many thanks to you. Now how does on set this to SOLVED?

  • Moderators

    Great, glad I could help.
    Just use the "edit" link on the right side of the post and edit the title by prepending [SOLVED] to it.

Log in to reply

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