Clear text selection when focus is lost

fixes #409
This commit is contained in:
Konstantinos Sideris 2018-09-25 18:06:11 +03:00
parent 7a288cc2cb
commit c9427c7f17
2 changed files with 11 additions and 1 deletions

View File

@ -69,7 +69,6 @@ TextLabel::TextLabel(const QString &text, QWidget *parent)
&TextLabel::adjustHeight);
document()->setDocumentMargin(0);
setFocusPolicy(Qt::NoFocus);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
setFixedHeight(0);
@ -94,6 +93,16 @@ TextLabel::TextLabel(const QString &text, QWidget *parent)
});
}
void
TextLabel::focusOutEvent(QFocusEvent *e)
{
QTextBrowser::focusOutEvent(e);
QTextCursor cursor = textCursor();
cursor.clearSelection();
setTextCursor(cursor);
}
void
TextLabel::mousePressEvent(QMouseEvent *e)
{

View File

@ -110,6 +110,7 @@ public:
protected:
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void focusOutEvent(QFocusEvent* e) override;
private slots:
void adjustHeight(const QSizeF &size) { setFixedHeight(size.height()); }