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. How to create a valid and "usable" QTextFrameFormat

How to create a valid and "usable" QTextFrameFormat

Scheduled Pinned Locked Moved General and Desktop
17 Posts 3 Posters 4.8k Views 3 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.
  • mrjjM mrjj

    @Nixxer
    hmm so it dont like format1.
    Only thing that spring to mind is the cursor thing. but firstCursorPosition should be fine too?

    If we look at sample code:

    QTextEdit *editor = new QTextEdit;
    QTextCursor cursor(editor->textCursor());
    cursor.movePosition(QTextCursor::Start);
    QTextFrame *topFrame = cursor.currentFrame();
    QTextFrameFormat topFrameFormat = topFrame->frameFormat();
    topFrameFormat.setPadding(16);
    topFrame->setFrameFormat(topFrameFormat);
    ...
    QTextCharFormat boldFormat;
    boldFormat.setFontWeight(QFont::Bold);
    cursor.insertText("A company", boldFormat);
    

    It looks like yours alot.

    N Offline
    N Offline
    Nixxer
    wrote on last edited by
    #8

    @mrjj
    One thing that differs is that i declare all my variables in the stack, while the example declares them in the heap, but i hope that all that works in the heap should work also in the stack and vice-versa...

    My intention was to make a QTextDocument, put in this a QTextFrame, put a text in it with a QTextCursor, create a QTextFrameFormat to be applied to the QTextFrame...

    mrjjM 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #9

      minimal sample that works for me

      QTextEdit *editor = new QTextEdit;
      QTextCursor cursor(editor->textCursor());
      cursor.movePosition(QTextCursor::Start);
      QTextFrame *topFrame = cursor.currentFrame();
      QTextFrameFormat topFrameFormat = topFrame->frameFormat();
      topFrameFormat.setPadding(16);
      topFrame->setFrameFormat(topFrameFormat);
      cursor.insertBlock();
      cursor.insertText("321 City Street");

      1 Reply Last reply
      0
      • N Nixxer

        @mrjj
        One thing that differs is that i declare all my variables in the stack, while the example declares them in the heap, but i hope that all that works in the heap should work also in the stack and vice-versa...

        My intention was to make a QTextDocument, put in this a QTextFrame, put a text in it with a QTextCursor, create a QTextFrameFormat to be applied to the QTextFrame...

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #10

        @Nixxer
        Well it crashes before you run out of scope so I doubt it is related to the stack :)

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #11

          @Nixxer said:
          One thing I wondered:
          The sample does not new / create a QTextDocument as far as I can see.
          I wonder if it is needed to do , or I simply don't understand what you want to do :)

          N 1 Reply Last reply
          0
          • mrjjM mrjj

            @Nixxer said:
            One thing I wondered:
            The sample does not new / create a QTextDocument as far as I can see.
            I wonder if it is needed to do , or I simply don't understand what you want to do :)

            N Offline
            N Offline
            Nixxer
            wrote on last edited by
            #12

            @mrjj
            I'll try this snippet, maybe I'll learn something...

            I begin with the QTextDocument because I'd like to make a program to make documents, like a list of properties of a client, so I thought that I could make a QTextDocument in which inserting one after one these properties with different frames and their ...

            Maybe I took the problem by the wrong way...

            Btw, I was thinking to make this program as a exercise to begin to "mess" with Qt...

            mrjjM 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #13

              Hi,

              In that case, I'd recommend the excellent "C++ GUI Programming with Qt 4 (2nd Edition)" from Mark Summerfield and Jasmin Blanchette. Although it's Qt 4, it still relevant for Qt 5 and there's a good chapter about QTextDocument

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

              N 1 Reply Last reply
              0
              • N Nixxer

                @mrjj
                I'll try this snippet, maybe I'll learn something...

                I begin with the QTextDocument because I'd like to make a program to make documents, like a list of properties of a client, so I thought that I could make a QTextDocument in which inserting one after one these properties with different frames and their ...

                Maybe I took the problem by the wrong way...

                Btw, I was thinking to make this program as a exercise to begin to "mess" with Qt...

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #14

                @Nixxer
                Like a database with clients and their properties ?
                Depending on your coding skills, construction a RTF doc on the fly is maybe a somewhat hardcore start :)

                N 1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  In that case, I'd recommend the excellent "C++ GUI Programming with Qt 4 (2nd Edition)" from Mark Summerfield and Jasmin Blanchette. Although it's Qt 4, it still relevant for Qt 5 and there's a good chapter about QTextDocument

                  N Offline
                  N Offline
                  Nixxer
                  wrote on last edited by
                  #15

                  @SGaist
                  Thanks for the suggestion! If I can learn something for Qt 5, I'll gladly read this book...

                  1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Nixxer
                    Like a database with clients and their properties ?
                    Depending on your coding skills, construction a RTF doc on the fly is maybe a somewhat hardcore start :)

                    N Offline
                    N Offline
                    Nixxer
                    wrote on last edited by
                    #16

                    @mrjj
                    It's right, but I prefer to learn starting from "real" problems (I'm an self-taught "programmer")...

                    mrjjM 1 Reply Last reply
                    0
                    • N Nixxer

                      @mrjj
                      It's right, but I prefer to learn starting from "real" problems (I'm an self-taught "programmer")...

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #17

                      @Nixxer
                      Well thats really understandable. More fun when it's real.
                      I can only second SGaist book suggestion.
                      I found it free on
                      http://www.bogotobogo.com/cplusplus/files/c-gui-programming-with-qt-4-2ndedition.pdf
                      (takes a moment to load)

                      Good luck

                      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