
Originally Posted by
Alundra
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:
#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();
}
#include <QtGui>
class LineEdit : public QLineEdit {
Q_OBJECT
public:
LineEdit(QWidget *parent = 0) : QLineEdit(parent) { setReadOnly(true); }
protected:
void mouseDoubleClickEvent(QMouseEvent *) {
setReadOnly(false);
setFocus();
activateWindow();
}
};
#include "main.moc"
int main(int argc, char **argv) {
QApplication app(argc, 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)?
Bookmarks