Skip to content

Commit

Permalink
fix: 修复大多数按钮不响应enter事件
Browse files Browse the repository at this point in the history
修复大多数按钮不响应enter事件,仅支持DApplication应用

Log: 修复大多数按钮不响应enter事件
Bug: https://pms.uniontech.com/bug-view-253935.html
Influence: 按钮响应键盘回车事件
  • Loading branch information
Whale107 authored and kegechen committed May 9, 2024
1 parent 4259087 commit 4f72ca0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/widgets/dapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,22 @@ bool DApplication::notify(QObject *obj, QEvent *event)
}
}

// Qt 6.4 引入了 QPlatformTheme::ThemeHint::ButtonPressKeys
// 可以通过主题插件 themeHint 返回一个按键列表,按钮应该响应列表中的按键
// see https://github.com/linuxdeepin/qt5integration/pull/20
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
if (event->type() == QEvent::KeyPress && obj == focusWidget()) {
if (auto keyEvent = dynamic_cast<QKeyEvent *>(event)) {
if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) {
if (auto btn = qobject_cast<QAbstractButton *>(obj)) {
Q_EMIT btn->clicked();
return true;
}
}
}
}
#endif

if (event->type() == QEvent::ApplicationFontChange) {
// ApplicationFontChange 调用 font() 是 ok 的,如果在 fontChanged 中调用在某些版本中会出现 deadlock
DFontSizeManager::instance()->setFontGenericPixelSize(static_cast<quint16>(DFontSizeManager::fontPixelSize(font())));
Expand Down

0 comments on commit 4f72ca0

Please sign in to comment.