Is it possible to have an outline text on a QGraphicTextItem? I cannot find anyway to achieve that!
thank you for your help
Is it possible to have an outline text on a QGraphicTextItem? I cannot find anyway to achieve that!
thank you for your help
You need to set a pen and a brush.
If you add a text document, you can create your own layout using QTextCharFormat etc...
Edit: it is not nice to ask the same question on multiple forums. It shows a lack of respect and trust.
Last edited by tbscope; 17th October 2010 at 06:30.
Hello, thank you for your hints but i do not see how the painterpath can let me have rich text as it works within QGraphicsTextItem... where do i collect it...can you explain me more
well qgraphictextitem is as opposed to qgraphicsimpletextitem and let me reedit the text, is it not?
As I already said:
Use a QTextDocument. Iterate over the textblocks, for each cursor position, get the text format, set an outline pen in that format.
It's already there for you to use: http://doc.qt.nokia.com/4.7/qtextcha...setTextOutline
hi, thank you very much, it is clearer now... i do apologize i don't have your expertise.
Should i put this method reimplementing the paint of my QGraphicsTextItem
You do not need to reimplement anything.
Instead of using a plain or rich text in the graphics text item, use a text document. Then go down a level to access the text blocks and set the character format for those blocks.
http://doc.qt.nokia.com/4.7/qgraphic...ml#setDocument
http://doc.qt.nokia.com/4.7/qtextdocument.html
http://doc.qt.nokia.com/4.7/qtextblock.html
Edit:
If you use a text cursor, you can directly insert text with a certain format.
http://doc.qt.nokia.com/4.7/qtextcursor.html#insertText
this example uses text objects, but it can be usefull for your situation too:
http://doc.qt.nokia.com/4.7/richtext-textobject.html
okie
the user is the one that does edit the text of this qgraphicstextitem... i am not inserting any programmatically like in the richtext object example
if i try to insert the following as i am initializing my own implementation of qgraphicstextitem
Qt Code:
QTextCharFormat format; format.setTextOutline ( outlinePen ); QTextCursor cursor; cursor.setCharFormat ( format ); setTextCursor(cursor);To copy to clipboard, switch view to plain text mode
i got a cursor but i cannot edit (enter any text anymore) that is where i am stuck. If i remove those lines i can edit normally (but without outlined text!)
Well, I made myself a test program and it works perfectly here, with the outline or any styling I want. Including the editing.
You might want to provide a little toolbar with editing options too if you want.
Edit: here's part of the code for inspiration:
Qt Code:
ui->setupUi(this); ui->graphicsView->setScene(scene); QTextCharFormat charFormat; charFormat.setTextOutline(outlinePen); cursor.insertText("Test", charFormat); textItem->setDocument(document); textItem->setTextInteractionFlags(Qt::TextEditable); scene->addItem(textItem);To copy to clipboard, switch view to plain text mode
Last edited by tbscope; 17th October 2010 at 20:16.
Bookmarks