Qt 6.11 is out! See what's new in the release
blog
Qt Development QLineEdit Cursor Color
-
I'm trying to customize the QLineEdit cursor (the blinking caret), especially its color and thickness. I’ve tried both
QPalette::TextandQLineEdit { color: xxx; }in stylesheet, but the cursor remains black regardless of these settings.I’ve confirmed that
QTextEditallows customizing cursor color via palette, butQLineEditdoes not respond to that. Even using a dark background, the insertion cursor remains hard to see.I also checked Qt source code and found the cursor is drawn in QWidgetLineControl::draw(), using
p.setPen(pal.text().color()). However, stylesheet seems to override palette partially.Is there an official or recommended way to override QLineEdit’s caret color? Or is subclassing + reimplementing
paintEvent()the only way?