
Originally Posted by
scarleton
but on the mouse down or something the selectAll is lost.
To prevent such behaviour, you'd have to filter out all unwanted events. But then you won't be able to do things as selecting parts of the input from the widget with the mouse and stuff. I think that what you really want is something like this:
public:
protected:
m_firstChar = true;
}
if(m_firstChar /* && !ke->text().isEmpty() */) { // the commented part is optional
clear();
m_firstChar = false;
}
}
private:
bool m_firstChar;
};
class MagicLineEdit : public QLineEdit {
public:
MagicLineEdit(QWidget *parent = 0) : QLineEdit(parent), m_firstChar(false) {}
protected:
void focusInEvent(QFocusEvent *e) {
m_firstChar = true;
QLineEdit::focusInEvent(e);
}
void keyPressEvent(QKeyEvent *ke) {
if(m_firstChar /* && !ke->text().isEmpty() */) { // the commented part is optional
clear();
m_firstChar = false;
}
QLineEdit::keyPressEvent(ke);
}
private:
bool m_firstChar;
};
To copy to clipboard, switch view to plain text mode
Bookmarks