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
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.
well having a toolbar is theplan but i have to pass the first hurdle.. so you mean just by placing
Qt Code:
QTextCharFormat format; format.setTextOutline ( outlinePen ); QTextCursor cursor; cursor.setCharFormat ( format ); setTextCursor(cursor);To copy to clipboard, switch view to plain text mode
on a qgraphicstextitem without anything extra this edits fine? do you do any setup to the QTextDocument attached to the qgraphicstextitem ?
was missing document()
----> QTextCursor cursor = QTextCursor(document());
it works well.... thank you very much for your excellent help
by the way ... it is not that i don't trust a forum if i post a question on different ones... but sometime you don't get answer on some (and i can understand that too). It is just that some issues are sometime blocking the progression of your work and you want to figure a solution as fast as possible.
Thanks again
Bookmarks