Fix multiple widget selection bug;

This commit is contained in:
jixiaoxu 2021-09-08 15:41:28 +08:00
parent d1c65e08d5
commit 9ea51f22ad
2 changed files with 20 additions and 0 deletions

View File

@ -278,6 +278,21 @@ void ResultView::onMenuTriggered(QAction *action)
}
}
void ResultView::mousePressEvent(QMouseEvent *event)
{
m_mousePressIndex = indexAt(event->pos());
return QTreeView::mousePressEvent(event);
}
void ResultView::mouseReleaseEvent(QMouseEvent *event)
{
QModelIndex index = indexAt(event->pos());
if (!index.isValid() or index != m_mousePressIndex) {
this->clearSelection();
}
return QTreeView::mouseReleaseEvent(event);
}
void ResultView::initConnections()
{
connect(this, &ResultView::startSearch, [ = ](const QString &keyword) {

View File

@ -33,6 +33,10 @@ public Q_SLOTS:
const bool &isExpanded();
void onMenuTriggered(QAction *);
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
void initConnections();
SearchResultModel * m_model = nullptr;
@ -40,6 +44,7 @@ private:
bool m_is_selected = false;
ResultViewDelegate * m_style_delegate = nullptr;
int m_count = 0;
QModelIndex m_mousePressIndex;
Q_SIGNALS:
void startSearch(const QString &);