[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)
{
ui->setupUi(this);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);QBrush redbrush(Qt::red); QPen blackpen(Qt::black); blackpen.setWidth(15); blackpen.setStyle(Qt::SolidLine); QFont font; font.setFamily("Times New Roman"); font.setPointSize(200); txt = new QGraphicsSimpleTextItem(); txt->setText("Hi"); txt->setFont(font); txt->setPen(blackpen); txt->setBrush(redbrush); scene->addItem(txt); }
@
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?
-
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?
-
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.