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 change the currentFont in a QTextEdit but leaving the formattation
Forum Updated to NodeBB v4.3 + New Features

How to change the currentFont in a QTextEdit but leaving the formattation

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 2 Posters 756 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    How did you create the "f" QFont object ?

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

    H 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      How did you create the "f" QFont object ?

      H Offline
      H Offline
      HenkCoder
      wrote on last edited by HenkCoder
      #3

      @SGaist The QFont object is passed as a parameter in the on_fontComboBox_currentFontChanged() function.
      Basically I put a font in the fontComboBox and passees the parameter.

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

        That does not answer the question which is how is that font object created ?

        From the looks of it, you are not just changing the font name but you are nuking the current one.

        What is usually done is grabbing the current font of an object, modify whatever property you want and then apply that modified font on the widget.

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

        H 1 Reply Last reply
        1
        • SGaistS SGaist

          That does not answer the question which is how is that font object created ?

          From the looks of it, you are not just changing the font name but you are nuking the current one.

          What is usually done is grabbing the current font of an object, modify whatever property you want and then apply that modified font on the widget.

          H Offline
          H Offline
          HenkCoder
          wrote on last edited by
          #5

          @SGaist Sorry I didn't understand what you said

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6
            QFont font = widget->font();
            font.setFamily("something");
            widget->setFont(font);
            

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

            H 2 Replies Last reply
            0
            • SGaistS SGaist
              QFont font = widget->font();
              font.setFamily("something");
              widget->setFont(font);
              
              H Offline
              H Offline
              HenkCoder
              wrote on last edited by
              #7

              @SGaist alright thanks, I'll try it. I'll keep you updated.

              1 Reply Last reply
              0
              • SGaistS SGaist
                QFont font = widget->font();
                font.setFamily("something");
                widget->setFont(font);
                
                H Offline
                H Offline
                HenkCoder
                wrote on last edited by
                #8

                @SGaist
                Hello, I tried the code you suggested. And it works yes, but an older problem appears again, this one

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

                  You should not apply fonts blindingly on QTextEdit if you want to have different fonts there you need to handle that à the document level.

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

                  H 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    You should not apply fonts blindingly on QTextEdit if you want to have different fonts there you need to handle that à the document level.

                    H Offline
                    H Offline
                    HenkCoder
                    wrote on last edited by
                    #10

                    @SGaist Can you explain more? I don't understand much, sorry I'm a beginner in Qt

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

                      You are using QTextEdit for custom editing, hence you want to only apply the font to the selected text and not the whole widget.

                      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

                      • Login

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