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. Write rich text into .odt file
QtWS25 Last Chance

Write rich text into .odt file

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 1.8k 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.
  • A Offline
    A Offline
    artwaw
    wrote on 21 Sept 2020, 17:58 last edited by
    #2

    Hi,
    as for holding/editing the rich text, you might want to think of QTextDocument class. There really is no need to reinvent the wheel, I think. QTextEdit, on the other hand, is perfect as rich text editor, I'd strongly advice to reconsider the UI design in that regard.

    For more information please re-read.

    Kind Regards,
    Artur

    T 1 Reply Last reply 21 Sept 2020, 18:01
    0
    • A artwaw
      21 Sept 2020, 17:58

      Hi,
      as for holding/editing the rich text, you might want to think of QTextDocument class. There really is no need to reinvent the wheel, I think. QTextEdit, on the other hand, is perfect as rich text editor, I'd strongly advice to reconsider the UI design in that regard.

      T Offline
      T Offline
      Tamfub
      wrote on 21 Sept 2020, 18:01 last edited by
      #3

      @artwaw
      Hi,
      Unfortunately there cannot be a textEdit in my project, so I was wondering if I could do the same with the bits that make the QTextDocument and put them inside it.

      A S 2 Replies Last reply 21 Sept 2020, 18:09
      0
      • T Tamfub
        21 Sept 2020, 18:01

        @artwaw
        Hi,
        Unfortunately there cannot be a textEdit in my project, so I was wondering if I could do the same with the bits that make the QTextDocument and put them inside it.

        A Offline
        A Offline
        artwaw
        wrote on 21 Sept 2020, 18:09 last edited by
        #4

        @Tamfub well, in theory you could, of course. Actual implementation would, of course, depend on which bits of functionality from QTextDocument you'd like to copy...
        However, since the problem lies within UI, I'd stick to keeping QTextDocument having your data. It would be easier, I think, this way as you can save formatted text directly.
        Actual implementation would then rather focus on manipulating the text (insert/edit/delete) and formatting it inside QTextDocument (and there is plethora of classes and methods to help you - all nicely described in the documentation). So you'd have to implement that actual functionality of interacting between whatever UI you have and the data in QTextDocument and not dive into details of saving in the right format.

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        0
        • T Tamfub
          21 Sept 2020, 18:01

          @artwaw
          Hi,
          Unfortunately there cannot be a textEdit in my project, so I was wondering if I could do the same with the bits that make the QTextDocument and put them inside it.

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 21 Sept 2020, 18:11 last edited by
          #5

          Hi,

          @Tamfub said in Write rich text into .odt file:

          @artwaw
          Hi,
          Unfortunately there cannot be a textEdit in my project, so I was wondering if I could do the same with the bits that make the QTextDocument and put them inside it.

          Out of curiosity, can you explain the reasons you can't have a QTextEdit in your UI ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply 21 Sept 2020, 18:15
          0
          • S SGaist
            21 Sept 2020, 18:11

            Hi,

            @Tamfub said in Write rich text into .odt file:

            @artwaw
            Hi,
            Unfortunately there cannot be a textEdit in my project, so I was wondering if I could do the same with the bits that make the QTextDocument and put them inside it.

            Out of curiosity, can you explain the reasons you can't have a QTextEdit in your UI ?

            T Offline
            T Offline
            Tamfub
            wrote on 21 Sept 2020, 18:15 last edited by Tamfub
            #6

            @SGaist
            Hello,
            the project I am working on is something like this:
            https://conclave-team.github.io/conclave-site/
            The client and server send data with QTcpSockets. The server side does not have a GUI (it is on the client side, with a textEdit), the client sends each Symbol and the server keeps them in a QList.
            Now, we would like to store this Symbols (that compose a rich text) in a local .odt file.
            I think it is unconvenient to send the whole textEdit->document() at every change inside the client textEdit.

            A 1 Reply Last reply 21 Sept 2020, 18:24
            0
            • T Tamfub
              21 Sept 2020, 18:15

              @SGaist
              Hello,
              the project I am working on is something like this:
              https://conclave-team.github.io/conclave-site/
              The client and server send data with QTcpSockets. The server side does not have a GUI (it is on the client side, with a textEdit), the client sends each Symbol and the server keeps them in a QList.
              Now, we would like to store this Symbols (that compose a rich text) in a local .odt file.
              I think it is unconvenient to send the whole textEdit->document() at every change inside the client textEdit.

              A Offline
              A Offline
              artwaw
              wrote on 21 Sept 2020, 18:24 last edited by
              #7

              @Tamfub I'd still stick with internal representation as QTextEdit, you can edit it as the symbols flow in.

              For more information please re-read.

              Kind Regards,
              Artur

              S 1 Reply Last reply 21 Sept 2020, 18:25
              0
              • A artwaw
                21 Sept 2020, 18:24

                @Tamfub I'd still stick with internal representation as QTextEdit, you can edit it as the symbols flow in.

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 21 Sept 2020, 18:25 last edited by
                #8

                @artwaw said in Write rich text into .odt file:

                @Tamfub I'd still stick with internal representation as QTextEdit, you can edit it as the symbols flow in.

                Agreed, establish a protocol to keep the documents in sync but there's no need to reinvent the wheel.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Tamfub
                  wrote on 21 Sept 2020, 18:32 last edited by
                  #9

                  Ok, I have a distributed application and I must apply the CRDT algorithm to keep consistency in shared documents. Since more than one clients may work on the same document (like in Google Docs), how can I keep more than one textEdit graphical element on the server? Maybe I'm not getting it at all.

                  A 1 Reply Last reply 21 Sept 2020, 18:34
                  0
                  • T Tamfub
                    21 Sept 2020, 18:32

                    Ok, I have a distributed application and I must apply the CRDT algorithm to keep consistency in shared documents. Since more than one clients may work on the same document (like in Google Docs), how can I keep more than one textEdit graphical element on the server? Maybe I'm not getting it at all.

                    A Offline
                    A Offline
                    artwaw
                    wrote on 21 Sept 2020, 18:34 last edited by
                    #10

                    @Tamfub you don't need QTextEdit on the server. Just QTextDocument that's being kept up to date.

                    For more information please re-read.

                    Kind Regards,
                    Artur

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 21 Sept 2020, 18:34 last edited by
                      #11

                      So you want to implement something like Google Docs ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        Tamfub
                        wrote on 21 Sept 2020, 18:46 last edited by Tamfub
                        #12

                        Yes, something like that. But if I have a Symbol like one of the first post:

                        Symbol s('H', QFont::Bold)
                        

                        can I create an empty QTextDocument and insert the Symbol character and properties inside it?

                        A 1 Reply Last reply 21 Sept 2020, 18:49
                        0
                        • T Tamfub
                          21 Sept 2020, 18:46

                          Yes, something like that. But if I have a Symbol like one of the first post:

                          Symbol s('H', QFont::Bold)
                          

                          can I create an empty QTextDocument and insert the Symbol character and properties inside it?

                          A Offline
                          A Offline
                          artwaw
                          wrote on 21 Sept 2020, 18:49 last edited by
                          #13

                          @Tamfub Of course.

                          For more information please re-read.

                          Kind Regards,
                          Artur

                          T 1 Reply Last reply 21 Sept 2020, 18:56
                          0
                          • A artwaw
                            21 Sept 2020, 18:49

                            @Tamfub Of course.

                            T Offline
                            T Offline
                            Tamfub
                            wrote on 21 Sept 2020, 18:56 last edited by
                            #14

                            @artwaw ok, how can I insert the character? Should I create a QTextBlock inside the QTextDocument or what?

                            A 1 Reply Last reply 21 Sept 2020, 19:09
                            0
                            • T Tamfub
                              21 Sept 2020, 18:56

                              @artwaw ok, how can I insert the character? Should I create a QTextBlock inside the QTextDocument or what?

                              A Offline
                              A Offline
                              artwaw
                              wrote on 21 Sept 2020, 19:09 last edited by
                              #15

                              @Tamfub You edit QTextDocument using QTextCursor (it is mentioned in QTextDocument documentation btw.).
                              Also worth reading before you begin is Rich Text Editing overview page.

                              It is a fair amount of reading but in my honest opinion - it is worth it.

                              For more information please re-read.

                              Kind Regards,
                              Artur

                              1 Reply Last reply
                              2
                              • T Offline
                                T Offline
                                Tamfub
                                wrote on 21 Sept 2020, 20:14 last edited by
                                #16

                                Fine, I'll give it a read then. Thank you both @artwaw and @SGaist! :)

                                1 Reply Last reply
                                1

                                11/16

                                21 Sept 2020, 18:34

                                • Login

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