QTextEdit : controlling cursor width and color

  • 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.

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

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

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

  • @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.

  • @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.

  • @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.

  • 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.