Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Clear text selection when focus is lost
Browse files Browse the repository at this point in the history
fixes #409
  • Loading branch information
mujx committed Sep 25, 2018
1 parent 7a288cc commit c9427c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/timeline/TimelineItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/timeline/TimelineItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class TextLabel : public QTextBrowser
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()); }
Expand Down

0 comments on commit c9427c7

Please sign in to comment.