Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Force always blinking cursor on QLineEdit



  • Hello all,

    I have a QLineEdit object on my forum where I want the cursor to always be blinking. I have been searching on the internet to see if others have done this before but it would seem that most people what to hide the cursor. I would like to always display the cursor.

    My first solution was to set the line edit to always have focus. If an action removed focus from the line edit, I would always reset the focus back to the QLineEdit. This worked until I realized that when I am tabbing through my form, my tab focus gets reset after a perform an action.

    I am pretty sure that I will need a subclass for the line edit. Not a problem since I already created a subclass of the line edit class that emits a mouse click signal.

    I also know that i will be modifying the paint event but I am not sure which properties I need to edit. Does any have any thoughts on the matter?



  • I think it's more complicated than subclassing QLineEdit. To implement a custom cursor or custom cursor behaviour I'm guessing you will need to write your own QLineEdit replacement since their is no abstract parent class for QLineEdit.


  • Lifetime Qt Champion

    Hi
    All the blinking is inside private/header class
    https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qwidgetlinecontrol.cpp.html#_ZN18QWidgetLineControl24setBlinkingCursorEnabledEb

    so i would try to extra the logic/code and make a thin
    wrapper around QLineEdit and override paintEvent and use
    the extracted code to let it blink when not having focus.

    That said, you are aware is highly uncommon for any platform to show
    a blinking cursor in all visible edits?



  • I want to show cursor in QLineEdit anyway too. My application is like AutoCAD, A graph window with a command line.
    When the graph window got the focus, it can send point at clicking and send F1-F12 event to command handler. User keyboard event will be forwarded to QLineEdit after filtering just like the QLineEdit is focused.


Log in to reply