QTextEdit : controlling cursor width and color
-
wrote on 10 Jan 2017, 15:10 last edited by Harry123 1 Oct 2017, 15:18
My problems with the QTextEdit blinking cursor are :
- The cursor is invisible over some background colors (the solution would be to set it to the antithesis of the background color)
- I would like the cursor to be wider when in overwrite mode
- 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.
-
My problems with the QTextEdit blinking cursor are :
- The cursor is invisible over some background colors (the solution would be to set it to the antithesis of the background color)
- I would like the cursor to be wider when in overwrite mode
- 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.
wrote on 10 Jan 2017, 15:21 last edited by@Harry123
have you read QTextEdit document?
I find there is a method to set the curcor width -
wrote on 10 Jan 2017, 15:23 last edited by
@Flotisable
Yes, I missed this one - I will be testing it. -
wrote on 10 Jan 2017, 15:57 last edited by
I find that set the
color
of theStyleSheet
can change the color of the cursor -
wrote on 11 Jan 2017, 11:18 last edited by Harry123 1 Nov 2017, 11:21
QTextEdit::setCursorWidth
works for the cursor width - thanks. It seems to needQTextEdit::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 implementingcaret-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.
-
QTextEdit::setCursorWidth
works for the cursor width - thanks. It seems to needQTextEdit::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 implementingcaret-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.
wrote on 11 Jan 2017, 12:19 last edited by@Harry123
for the text color, you can useQTextEdit
'ssetTextColor
method after setcolor
ofstyle sheet
.
for the frame border, maybe you can setborder
ofstyle 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.
-
wrote on 11 Jan 2017, 12:45 last edited by
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.
-
wrote on 12 Jan 2017, 16:16 last edited by Harry123 1 Dec 2017, 16:18
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/8