fix: enable touch screen scrolling for QScrollArea-based views#706
Conversation
The PageDetail and PageDriverInstallInfo views use QScrollArea to display content, which only responds to mouse wheel events by default. On touch screens, finger swipe gestures do not trigger scrolling, causing text selection to be activated instead. Register QScroller gestures on the affected QScrollArea widgets to enable kinetic touch scrolling. Extract scroller properties into named constants in MacroDefinition.h for reuse and maintainability. Files changed: - MacroDefinition.h: add SCROLLER_OVERSHOOT_DISTANCE_FACTOR, SCROLLER_OVERSHOOT_DRAG_RESIST_FACTOR, SCROLLER_DRAG_VELOCITY_SMOOTH_FACTOR - PageDetail.cpp: register QScroller on mp_ScrollArea - PageDriverInstallInfo.cpp: register QScroller on driver list scroll area Log: fix issue Bug: https://pms.uniontech.com/bug-view-366201.html
There was a problem hiding this comment.
Sorry @GongHeng2017, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
deepin pr auto review★ 总体评分:85分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // MacroDefinition.h
// 将宏定义改为类型安全的常量
const double SCROLLER_OVERSHOOT_DISTANCE_FACTOR = 0.3;
const double SCROLLER_OVERSHOOT_DRAG_RESIST_FACTOR = 0.3;
const double SCROLLER_DRAG_VELOCITY_SMOOTH_FACTOR = 0.6;
// 新增工具函数(建议放在如 ScrollerUtils.h/cpp 中)
#include <QScroller>
#include <QScrollerProperties>
void setupScrollerProperties(QWidget *widget)
{
if (!widget) return;
QScroller::grabGesture(widget, QScroller::LeftMouseButtonGesture);
QScrollerProperties sp;
sp.setScrollMetric(QScrollerProperties::OvershootScrollDistanceFactor, SCROLLER_OVERSHOOT_DISTANCE_FACTOR);
sp.setScrollMetric(QScrollerProperties::OvershootDragResistanceFactor, SCROLLER_OVERSHOOT_DRAG_RESIST_FACTOR);
sp.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, SCROLLER_DRAG_VELOCITY_SMOOTH_FACTOR);
QScroller *scroller = QScroller::scroller(widget);
if (scroller) {
scroller->setScrollerProperties(sp);
}
}
// PageDetail.cpp
// 替换原有 6 行代码为单次调用
mp_ScrollArea->setWidget(mp_ScrollWidget);
setupScrollerProperties(mp_ScrollArea);
hLayout->addWidget(mp_ScrollArea);
// PageDriverInstallInfo.cpp
// 替换原有 6 行代码为单次调用
area->setWidgetResizable(true);
setupScrollerProperties(area);
DWidget *frame = new DWidget(this); |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
The PageDetail and PageDriverInstallInfo views use QScrollArea to display content, which only responds to mouse wheel events by default. On touch screens, finger swipe gestures do not trigger scrolling, causing text selection to be activated instead.
Register QScroller gestures on the affected QScrollArea widgets to enable kinetic touch scrolling. Extract scroller properties into named constants in MacroDefinition.h for reuse and maintainability.
Files changed:
Log: fix issue
Bug: https://pms.uniontech.com/bug-view-366201.html