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 : controlling cursor width and color
QtWS25 Last Chance

QTextEdit : controlling cursor width and color

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 5.0k 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.
  • H Offline
    H Offline
    Harry123
    wrote on last edited by Harry123
    #1

    My problems with the QTextEdit blinking cursor are :

    1. The cursor is invisible over some background colors (the solution would be to set it to the antithesis of the background color)
    2. I would like the cursor to be wider when in overwrite mode
    3. Sometimes when changing the QTextEdit color and font I can end up with the artifact of a phantom cursor left painted over the QTextEdit (the real cursor itself is also displayed and can be moved around)

    I have not found any way to control the cursor's width and color and would be thankful for any hints for that and for how to avoid phantom cursors.

    FlotisableF 1 Reply Last reply
    0
    • H Harry123

      My problems with the QTextEdit blinking cursor are :

      1. The cursor is invisible over some background colors (the solution would be to set it to the antithesis of the background color)
      2. I would like the cursor to be wider when in overwrite mode
      3. Sometimes when changing the QTextEdit color and font I can end up with the artifact of a phantom cursor left painted over the QTextEdit (the real cursor itself is also displayed and can be moved around)

      I have not found any way to control the cursor's width and color and would be thankful for any hints for that and for how to avoid phantom cursors.

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      @Harry123
      have you read QTextEdit document?
      I find there is a method to set the curcor width

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Harry123
        wrote on last edited by
        #3

        @Flotisable
        Yes, I missed this one - I will be testing it.

        1 Reply Last reply
        0
        • FlotisableF Offline
          FlotisableF Offline
          Flotisable
          wrote on last edited by
          #4

          I find that set the color of the StyleSheet can change the color of the cursor

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Harry123
            wrote on last edited by Harry123
            #5

            @Flotisable

            QTextEdit::setCursorWidth works for the cursor width - thanks. It seems to need QTextEdit::update() to have immediate effect.

            QTextEdit::setStyleSheet("color:..." changes the cursor color, but unfortunately it also colors the frame border and may also color the text. There is a new draft for caret-color which unfortunately is not yet in the standard, although seems to be implemented in Firefox and also in Chrome.
            I wonder if I need to make a feature request for implementing caret-color.

            For the phantom cursor, something I do leaves a phantom cursor at the end of the text, which disappears after a full repaint. I would really like to avoid this artifact.

            FlotisableF 1 Reply Last reply
            0
            • H Harry123

              @Flotisable

              QTextEdit::setCursorWidth works for the cursor width - thanks. It seems to need QTextEdit::update() to have immediate effect.

              QTextEdit::setStyleSheet("color:..." changes the cursor color, but unfortunately it also colors the frame border and may also color the text. There is a new draft for caret-color which unfortunately is not yet in the standard, although seems to be implemented in Firefox and also in Chrome.
              I wonder if I need to make a feature request for implementing caret-color.

              For the phantom cursor, something I do leaves a phantom cursor at the end of the text, which disappears after a full repaint. I would really like to avoid this artifact.

              FlotisableF Offline
              FlotisableF Offline
              Flotisable
              wrote on last edited by
              #6

              @Harry123
              for the text color, you can use QTextEdit's setTextColor method after set color of style sheet.
              for the frame border, maybe you can set border of style sheet.

              I think anything about widget color can be solved by using style sheet, so maybe you can read Qt Style Sheet if there is any problem about widget color.

              as for phantom cursor, can you show some image and more detail?sorry, I don't understand well about what you said.

              1 Reply Last reply
              1
              • H Offline
                H Offline
                Harry123
                wrote on last edited by
                #7

                @Flotisable

                I already started doing that, but this is becoming a horrible mix of style-sheet overridden by commands such as setTextColor with nothing documented about which overrides which.
                Color in QTextEdit seems a bit of a mess. Maybe, as you said, better to stick to one only : either all or none style-sheet.
                The problem with style-sheets is that the latest CSS doesn't seem to be supported.

                For the phantom cursor, I'm still examining the problem.

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Harry123
                  wrote on last edited by Harry123
                  #8

                  Finally the all-CSS approach worked, avoiding all functions of QTextCharFormat or palette.

                  The following CSS tags worked for me : color, border-style, border-width, border-color, background-color.

                  Conclusion : Only use QTextEdit::setStyleSheet for changing the look - avoid all other functions like the plague.
                  I am disgusted with the amount of time that I wasted on this problem and the poor co-existence in QTextEdit of the style-sheet with all the other pertaining functions.

                  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