Hi,
Is it possible to hide the cursor of QLineEdit and show it when needed ?
It's because I have a widget I would enable edit only when one click on it, readOnly works but it has problem with cursor when changing.
Thanks
Hi,
Is it possible to hide the cursor of QLineEdit and show it when needed ?
It's because I have a widget I would enable edit only when one click on it, readOnly works but it has problem with cursor when changing.
Thanks
You need to derive class from QLineEdit and in the following situation you should make the control read only.
1. focusOutEvent.
2. returnPressed signal.
& on mouse click you can remove the read only status ...I think that is the behaviour you want...
https://bugreports.qt-project.org/browse/QTBUG-37686
this problem, it's my bug report.
If you want the widget to have keyboard focus after being double-clicked then set focus on it there. I don't see any Qt bug there. I also don't understand what you are trying to do. You don't have to manipulate "readOnly" property to make a widget gain or lose focus.
The problem is the cursor is not visible and using setFocus() that doesn't show it too, you can try the code I have write in the BugReport, that show the problem.
To have the cursor visible, when double click (on the sample of the bug report), you have to use keyboard, only when you use keyboard the cursor is visible again.
As I said your test report is broken, at least when using Qt4.
I don't have any problems with the cursor using the following code:
Qt Code:
#include <QtGui> Q_OBJECT public: protected: setReadOnly(false); setFocus(); activateWindow(); } }; #include "main.moc" int main(int argc, char **argv) { LineEdit le; le.show(); le.setText("ABC"); return app.exec(); }To copy to clipboard, switch view to plain text mode
Still, the real question is why do you want to use "readOnly" here? You don't need to mark a widget read-only to not see the cursor. Just focus-out of the widget and/or don't accept focus in situations when you don't want to. Maybe you just need to change the focus policy (e.g. to Qt::ClickFocus)?
Last edited by wysota; 3rd June 2014 at 15:28.
Using Qt4 the problem is not there :
http://www.qtcentre.org/threads/5848...658#post260658
Qt::ClickFocus is maybe the good way to go here, I will try it.
Bookmarks