WYSIWYG text editor approach? QGraphicsScene + text object?



  • Hello,

    Are there any ready-available examples of this? I want a functionality akin to Photoshop text function.

    I'm thinking about subclassing QTextEdit and QGraphicsScene and placing this text object upon pressing a button. Then, when you click on this object, additional text editing tools become available - so you can set parts of text to bold, italic, modify color and not much else. And then you would be able to change the object's position - and I think that's available in QGraphicsScene by default.

    Is this a reasonable way to approach this?

    Edit:

    I want a background picture, as a QBrush, for the background of QGraphicsScene. Let's say I want to add a fancy caption to it or something like that.
    So the possible steps would be:
    (1) Press the text button. Text editing means appear on QGraphicsScene
    () Position the text
    (
    ) Edit the text, including font, size, etc.
    (2) Once it's done, an easy approach would be to 'finalize' the text and apply it to the background picture. A bit harder one would be to save the state of all the text objects (a layer of sorts) so they could be loaded and edited later.



  • Maybe it's good idea to consider using some kind of Qt Quick frontend for this? Prototyping the functionality you mention with QML seems to me much easier and faster then with pure QGraphicsScene. But It depends on how much low-level stuff and quantity of text objects you'll need there.



  • "QGraphicsTextItem":http://qt-project.org/doc/qt-4.8/qgraphicstextitem.html seems apropriate solution for you problem.
    You can style it using html.

    How to use it with double click editing, moving etc, you can take a look at Diagram Scene example.

    Regards,
    Jake



  • Thanks, that seems to be a fine solution.
    However, I have a problem: I cannot format separate parts of the text. When I set html code manually, the formatting works correctly. In the example, bold, italic, and other things work on whole QGraphicsTextItems only. As in, item->setFont, setBrush, etc.

    [quote author="Jake007" date="1331468237"]"QGraphicsTextItem":http://qt-project.org/doc/qt-4.8/qgraphicstextitem.html seems apropriate solution for you problem.
    You can style it using html.

    How to use it with double click editing, moving etc, you can take a look at Diagram Scene example.

    Regards,
    Jake[/quote]



  • All right, I got it.

    QTextCharFormat applied to my subclassed QGraphicsTextItem using QGraphicsTextItem::textCursor().mergeCharFormat. This way I can change formatting on the selection only.


Log in to reply
 

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