PDA

View Full Version : Hide blinking cursor from QLineEdit



ashtray4241
7th August 2014, 12:47
Hi,

I need to hide the blinking cursor (caret) of QLineEdit permanently.
But at the same time, I want the QLineEdit to be editable (so readOnly and setting editable false is not an option for me).

I am changing the Background color of the QLineEdit, when it is in focus, so I will know which QLineEdit widget is getting edited.
For my requirement, cursor (the blinking text cursor) display should not be there.

I have tried styleSheets, but I can't get the cursor hidden ( {setting color:transparent; text-shadow:0px 0px 0px black;} )

Can someone please let me know how can I achieve this?

Thanks,
Ash

Rajesh.Rathod
7th August 2014, 14:26
Please see below link about bug reported on qt forum for QLineEdit cursor...

https://qt.gitorious.org/qt/sroedals-qt/commit/9ef61d3d1e53d32dc2568cbfb9f8ff5b19cb4ffc

I don't about the version but may be it's related...

ashtray4241
7th August 2014, 14:30
Thanks for the reply. I also saw that, but that bug report is posted 4 years ago, so I am not sure about its status.

d_stranz
8th August 2014, 19:12
I need to hide the blinking cursor (caret) of QLineEdit permanently.
But at the same time, I want the QLineEdit to be editable (so readOnly and setting editable false is not an option for me).


So, put yourself in the place of the person using your software. They have clicked or tabbed over to the edit box and they want to change something in it. Every other app in the universe shows them a blinking caret cursor that not only indicates that they can edit, but also shows them where in the text they are editing.

Your implementation won't provide them any feedback at all. Nothing to show them that the control has edit focus, nothing to show them where they are about to make a change. If I were the user, I'd keep trying to click the edit box, because I expect it to react in the same way as every other app I use. Eventually I would give up and file a bug report.

So why on earth would you want to implement a behavior that is totally different from what users expect?

ashtray4241
11th August 2014, 08:32
I totally understand your concern.
But in my requirement, we have a LCD panel of a printer. In these InputBoxes (they are for numeric input only, by using validator), there is no way to press Backspace or move the cursor anywhere without typing a number. But the widget on which the focus is there, is having blue color and the other widgets are white in color. So the end user is aware of the widget where editing is done
Also, as soon as focus shifts on the widget, the complete value is selected (so, any new entry after focus is obtained, replaces the earlier value). Selected (highlighted) color is same shade of blue as the in-focus widget background color.

So, basically, as per the design team, cursor is unwanted in these widgets (as end user doesn't have any control over the cursor anyway)

wysota
11th August 2014, 10:26
I totally understand your concern.
But in my requirement, we have a LCD panel of a printer. In these InputBoxes (they are for numeric input only, by using validator), there is no way to press Backspace or move the cursor anywhere without typing a number. But the widget on which the focus is there, is having blue color and the other widgets are white in color. So the end user is aware of the widget where editing is done
Also, as soon as focus shifts on the widget, the complete value is selected (so, any new entry after focus is obtained, replaces the earlier value). Selected (highlighted) color is same shade of blue as the in-focus widget background color.

So, basically, as per the design team, cursor is unwanted in these widgets (as end user doesn't have any control over the cursor anyway)

So you mean that if I click on the widget, then enter numbers 1234 and then click between "2" and "3" then the cursor is not moved there and pressing "5" will not result in string "12534" but rather "12345"?

ashtray4241
11th August 2014, 11:35
So you mean that if I click on the widget, then enter numbers 1234 and then click between "2" and "3" then the cursor is not moved there and pressing "5" will not result in string "12534" but rather "12345"?
Yeah. Cursor doesn't move. We have basically two kind of widgets. One is normal Input box, which accepts all charaters, cursor can be displayed, moved etc and another is a numeric input box, where cursor position cannot be moved. After every focus received event, the new value will replace older value, and while focus is set on the widget, cursor will not be manually moved (it can only move one space at a time when entering the numeric value). So the result in the use case you mentioned will be 12345 only.

It may not be too user friendly, but the design department has this requirement. Currently we are using PEG where the cursor is not visible. We are porting the device to QT from PEG, and design department wants the same look and feel.

wysota
11th August 2014, 11:44
You can always subclass QLineEdit and reimplement its paint event. You can check the class's source code to see how QLineEdit draws itself, it will probably take you some time but at the end you should be able to identify a call that you can override (e.g. in the style) to get the desired behavior.