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. QtextEdit: custom text edition
Forum Updated to NodeBB v4.3 + New Features

QtextEdit: custom text edition

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.4k Views 2 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.
  • N Offline
    N Offline
    NicolasS
    wrote on 5 Apr 2017, 20:12 last edited by
    #1

    Hi all,

    I'd like to create a text editor allowing a user to add variables from a predefined list.

    1. Once the variable is added, it should be treated as a block, it means :
    • prevent the user from editing the text content,
    • allow deleting the whole variable only
    • prevent the cursor from blinking when the user click inside the text content
    1. I would also need to format it in a nice way (with a custom font style and a border around it).

    As a newbie with QTextEdit, I'd like some suggestion on which class could help me to achieve my goal.

    Thanks by advance

    1 Reply Last reply
    1
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 5 Apr 2017, 20:35 last edited by mrjj 4 May 2017, 20:35
      #2

      Hi
      I assume you can do it with
      http://doc.qt.io/qt-5/qtextobjectinterface.html#details
      Maybe you can cheat at bit and use images
      http://doc.qt.io/qt-5/qtsvg-richtext-textobject-example.html
      Render nice text and border to image and show it. Im not sure if you can
      interact with it. like clicking so maybe your own widget is easier.

      1 Reply Last reply
      4
      • N Offline
        N Offline
        NicolasS
        wrote on 6 Apr 2017, 06:33 last edited by
        #3

        Very nice. It's definitely be a good start !
        Thanks @mrjj

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rosh
          wrote on 31 Jan 2019, 02:13 last edited by
          #4

          @NicolasS was you able to implement your text editor with QTextObjectInterface ? I'm working on the similar problem, but additionally I need to handle mouse interactions with those custom "variables" (so each formatted block would have its context menu and can be drag n drop'ed, etc.).

          1 Reply Last reply
          0
          • N Offline
            N Offline
            NicolasS
            wrote on 31 Jan 2019, 08:02 last edited by
            #5

            Hello @rosh,

            It was a little bit of a hack but we managed to make it works.
            We represented those variables as images (we don't need standard images in our case).
            The steps were:

            1. Create a new handler for QTextFormat::ImageObject which inherits from QObject and QTextObjectInterface.
            2. Register this handler
            3. Each time a new variable has to be inserted to the document (via mime data in our case), a QTextImageFormat object is created with the right configuration (we use setProperty/property). Finaly, the variable is inserted through:
              cursor.insertText(QString(QChar::ObjectReplacementCharacter), imgFormat);

            Hope this help

            1 Reply Last reply
            2

            • Login

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