[Solved] outline on a QGraphicsTextItem
-
Without re-implementing the paint method?! hum, I'm afraid not...
However, you can you use "QGraphicsSimpleTextItem":http://doc.trolltech.com/4.6/qgraphicssimpletextitem.html?
If so, you can use setPen to set the outline color and setBrush to transparent. -
hello thank you for your answer...
well QGrahicsSimpleTextItem, is not rich text and does not let me reedit the text.
So reimplementing the paint method is what i am trying to figure out but unfortunately i cannot see how to grab the text to addit to a QPainterPath (if this mecanism can work!)
-
Can you post the code here?
-
Here's the code.
Context:
A widget is created in designer with a QGraphicsView.
A QGraphicsScene pointer is defined as a private member of the widget.
A QTextDocument is defined as a private member of the widget (although that is not necessary, the document of the QGraphicsTextItem can be used too)
A QGraphicsTextItem is defined as a private member of the widget.@
ui->setupUi(this);scene = new QGraphicsScene(ui->graphicsView);
ui->graphicsView->setScene(scene);document = new QTextDocument;
QTextCharFormat charFormat;
charFormat.setFont(QFont("times", 24));QPen outlinePen = QPen (QColor(255, 0, 0), 1, Qt::SolidLine);
charFormat.setTextOutline(outlinePen);QTextCursor cursor = QTextCursor(document);
cursor.insertText("Test", charFormat);textItem = new QGraphicsTextItem();
textItem->setDocument(document);
textItem->setTextInteractionFlags(Qt::TextEditable);scene->addItem(textItem);
@ -
Thanks for the code. =)
I've just asked that because probably someone will have the same problem in the future and a "I solved it" message will not help them =)