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. Qt Development QLineEdit Cursor Color
Forum Updated to NodeBB v4.3 + New Features

Qt Development QLineEdit Cursor Color

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 47 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.
  • B Offline
    B Offline
    byrAlpha
    wrote last edited by
    #1

    I'm trying to customize the QLineEdit cursor (the blinking caret), especially its color and thickness. I’ve tried both QPalette::Text and QLineEdit { color: xxx; } in stylesheet, but the cursor remains black regardless of these settings.

    I’ve confirmed that QTextEdit allows customizing cursor color via palette, but QLineEdit does 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?

    1 Reply Last reply
    0
    • HansonH Offline
      HansonH Offline
      Hanson
      wrote last edited by Hanson
      #2

      @byrAlpha Hi, You can try this.
      https://stackoverflow.com/questions/68769475/how-to-set-the-color-of-caret-blinking-cursor-in-qlineedit

      “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”
      —— Martin Golding

      1 Reply Last reply
      2

      • Login

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