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. Copy & Paste of custom text objects?

Copy & Paste of custom text objects?

Scheduled Pinned Locked Moved Solved General and Desktop
qtextobjectinte
8 Posts 2 Posters 2.6k Views
  • 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.
  • R Offline
    R Offline
    Ramin
    wrote on last edited by A Former User
    #1

    How can one enable copy and paste operations of custom text objects in a QTextEditor based on QTextObjectInterface and ObjectReplacementCharacter?

    I know selection, copy/paste, toPlaintext(), toHtml() and similar functions just ignore custom text objects. But if I were to make a radical change (derive and implement my own classes) then where would I begin? What direction shall I look?

    Thanks for any advise.

    raven-worxR 1 Reply Last reply
    0
    • R Ramin

      How can one enable copy and paste operations of custom text objects in a QTextEditor based on QTextObjectInterface and ObjectReplacementCharacter?

      I know selection, copy/paste, toPlaintext(), toHtml() and similar functions just ignore custom text objects. But if I were to make a radical change (derive and implement my own classes) then where would I begin? What direction shall I look?

      Thanks for any advise.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Ramin
      this is currently not possible: QTBUG-14487
      You have to create the mime data yourself.
      E.g. for QTextEdit you need to reimplement QMimeData * QTextEdit::createMimeDataFromSelection() const

      And replace your replace character with the data in the way you want it to be represented. (in text/plain, text/html ...)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      R 1 Reply Last reply
      2
      • raven-worxR raven-worx

        @Ramin
        this is currently not possible: QTBUG-14487
        You have to create the mime data yourself.
        E.g. for QTextEdit you need to reimplement QMimeData * QTextEdit::createMimeDataFromSelection() const

        And replace your replace character with the data in the way you want it to be represented. (in text/plain, text/html ...)

        R Offline
        R Offline
        Ramin
        wrote on last edited by
        #3

        @raven-worx Thanks, are there any architectural documents anywhere that I can use to understand the relationships between various classes ?

        What you explain seems like something I can do except you know the big picture and I have no idea where to start!

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ramin
          wrote on last edited by
          #4

          @raven-worx I do see there is a patch on that link, so if I build QT from source with that patch would this enable the copy/paste?

          raven-worxR 1 Reply Last reply
          0
          • R Offline
            R Offline
            Ramin
            wrote on last edited by
            #5

            @raven-worx I get what you are saying , and if there are no comprehensive documents about the way QTextEdit or related classes work then I guess reading createMimeDataFromSelection() and replacing it is the only way forward. I just want to know if there is a less intrusive way without patching QT.

            raven-worxR 1 Reply Last reply
            0
            • R Ramin

              @raven-worx I do see there is a patch on that link, so if I build QT from source with that patch would this enable the copy/paste?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Ramin said in [QTextObjectInterface] Copy & Paste of custom text objects?:

              I do see there is a patch on that link, so if I build QT from source with that patch would this enable the copy/paste?

              maybe, but seems like this patch is for Qt 4.7. It may be not applicable for Qt 5. In the worst case you have to do conflict resolution.

              @Ramin said in [QTextObjectInterface] Copy & Paste of custom text objects?:

              Thanks, are there any architectural documents anywhere that I can use to understand the relationships between various classes ?
              What you explain seems like something I can do except you know the big picture and I have no idea where to start!

              about what relationships between various classes are you talking? The best resource are the docs for the specific class. They normally explain the relationship pretty well.

              The createMimeDataFromSelection() method is called internally by QTextEdit whenever you press Ctrl+C or copy from the context menu, etc.

              QMimeData * QTextEdit::createMimeDataFromSelection() const
              {
                     QMimeData* mimeData = new QMimeData;
                     
                     QTextCursor c = this->cursor();
                     
                     QString plainTextStr = c.selectedText();
                     // replace 'QChar::ObjectReplacementCharacter' in plainTextStr
                     mimeData->setText( plainTextStr );
              
                     // html is a bit more tricky: use 'QTextDocumentFragment selection = c.selection()'
              
                     return mimeData;
              }
              

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              2
              • R Ramin

                @raven-worx I get what you are saying , and if there are no comprehensive documents about the way QTextEdit or related classes work then I guess reading createMimeDataFromSelection() and replacing it is the only way forward. I just want to know if there is a less intrusive way without patching QT.

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by raven-worx
                #7

                @Ramin said in [QTextObjectInterface] Copy & Paste of custom text objects?:

                I just want to know if there is a less intrusive way without patching QT.

                actually no.
                When you also want to support pasting of your custom text object you need to define the properties to be able to properly recreate it later on.
                So i doubt that there is a generic way to support this (without providing a proper API).

                On a quick glance on the patch i also just see the HTML export (but maybe this is also used to create the plain-text, i don't know) and no pasting.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                R 1 Reply Last reply
                1
                • raven-worxR raven-worx

                  @Ramin said in [QTextObjectInterface] Copy & Paste of custom text objects?:

                  I just want to know if there is a less intrusive way without patching QT.

                  actually no.
                  When you also want to support pasting of your custom text object you need to define the properties to be able to properly recreate it later on.
                  So i doubt that there is a generic way to support this (without providing a proper API).

                  On a quick glance on the patch i also just see the HTML export (but maybe this is also used to create the plain-text, i don't know) and no pasting.

                  R Offline
                  R Offline
                  Ramin
                  wrote on last edited by
                  #8

                  @raven-worx Thanks for this. I'll dig into it and see where I get stuck!

                  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