From 97bcd8257d7a1b4b853dab60c0dc26fa23313b39 Mon Sep 17 00:00:00 2001 From: lixueman Date: Thu, 20 Oct 2022 09:10:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A6=E6=91=B8=E6=BB=91=E5=8A=A8=E5=9B=9E?= =?UTF-8?q?=E5=BC=B9=E5=8A=A8=E7=94=BB=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/UserInterface/ListView/listview.cpp | 26 ++++++++++++++++++++++--- src/UserInterface/ListView/listview.h | 3 ++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/UserInterface/ListView/listview.cpp b/src/UserInterface/ListView/listview.cpp index f781921..89be87b 100755 --- a/src/UserInterface/ListView/listview.cpp +++ b/src/UserInterface/ListView/listview.cpp @@ -29,6 +29,7 @@ ListView::ListView(QWidget *parent/*, int width, int height, int module*/): this->h = 540; this->module = 1; initWidget(); + setAttribute(Qt::WA_AcceptTouchEvents); m_listmodel = new QStandardItemModel(this); this->setModel(m_listmodel); m_ukuiMenuInterface = new UkuiMenuInterface; @@ -95,6 +96,21 @@ void ListView::updateData(QVector data) } } +bool ListView::event(QEvent *e) +{ + switch (e->type()) { + case QEvent::TouchBegin: + m_scrollbarState = false; + break; + case QEvent::ChildRemoved: + m_scrollbarState = true; + break; + default: + break; + } + return QListView::event(e); +} + void ListView::onClicked(QModelIndex index) { QVariant var = m_listmodel->data(index, Qt::DisplayRole); @@ -119,14 +135,18 @@ void ListView::onClicked(QModelIndex index) void ListView::enterEvent(QEvent *e) { Q_UNUSED(e); - this->selectionModel()->clear(); - this->verticalScrollBar()->setVisible(true); + if (m_scrollbarState) { + this->selectionModel()->clear(); + verticalScrollBar()->setVisible(true); + } } void ListView::leaveEvent(QEvent *e) { Q_UNUSED(e); - this->verticalScrollBar()->setVisible(false); + if (m_scrollbarState) { + verticalScrollBar()->setVisible(false); + } } void ListView::paintEvent(QPaintEvent *e) diff --git a/src/UserInterface/ListView/listview.h b/src/UserInterface/ListView/listview.h index ff39d9b..f9125e8 100755 --- a/src/UserInterface/ListView/listview.h +++ b/src/UserInterface/ListView/listview.h @@ -49,11 +49,12 @@ protected: void leaveEvent(QEvent *e) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *e) override; void keyPressEvent(QKeyEvent *e); - + bool event(QEvent *e); private: int w = 0; int h = 0; int m_preRowCount; + bool m_scrollbarState = true; private Q_SLOTS: