Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. WYSIWYG text editor approach? QGraphicsScene + text object?
Forum Updated to NodeBB v4.3 + New Features

WYSIWYG text editor approach? QGraphicsScene + text object?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wolf-S
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vladimir_s
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jake007
        wrote on last edited by
        #3

        "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


        Code is poetry

        1 Reply Last reply
        0
        • W Offline
          W Offline
          Wolf-S
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Wolf-S
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved