Skip to content

Commit 4f72ca0

Browse files
Whale107kegechen
authored andcommitted
fix: 修复大多数按钮不响应enter事件
修复大多数按钮不响应enter事件,仅支持DApplication应用 Log: 修复大多数按钮不响应enter事件 Bug: https://pms.uniontech.com/bug-view-253935.html Influence: 按钮响应键盘回车事件
1 parent 4259087 commit 4f72ca0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/widgets/dapplication.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,22 @@ bool DApplication::notify(QObject *obj, QEvent *event)
15391539
}
15401540
}
15411541

1542+
// Qt 6.4 引入了 QPlatformTheme::ThemeHint::ButtonPressKeys
1543+
// 可以通过主题插件 themeHint 返回一个按键列表,按钮应该响应列表中的按键
1544+
// see https://github.com/linuxdeepin/qt5integration/pull/20
1545+
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
1546+
if (event->type() == QEvent::KeyPress && obj == focusWidget()) {
1547+
if (auto keyEvent = dynamic_cast<QKeyEvent *>(event)) {
1548+
if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) {
1549+
if (auto btn = qobject_cast<QAbstractButton *>(obj)) {
1550+
Q_EMIT btn->clicked();
1551+
return true;
1552+
}
1553+
}
1554+
}
1555+
}
1556+
#endif
1557+
15421558
if (event->type() == QEvent::ApplicationFontChange) {
15431559
// ApplicationFontChange 调用 font() 是 ok 的,如果在 fontChanged 中调用在某些版本中会出现 deadlock
15441560
DFontSizeManager::instance()->setFontGenericPixelSize(static_cast<quint16>(DFontSizeManager::fontPixelSize(font())));

0 commit comments

Comments
 (0)