触摸滑动回弹动画异常问题

This commit is contained in:
lixueman 2022-10-20 09:10:15 +08:00
parent 0f356b2d3c
commit 97bcd8257d
2 changed files with 25 additions and 4 deletions

View File

@ -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<QStringList> 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)

View File

@ -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: