linuxdeepin / qt5integration

Qt platform theme integration plugins for DDE.
Other
36 stars 47 forks source link

fix: Button can't reponse Return/Enter key #207

Closed FeiWang1119 closed 9 months ago

FeiWang1119 commented 9 months ago

add the keys Return/Enter support in deepintheme

Issue: https://github.com/linuxdeepin/developer-center/issues/5852

FeiWang1119 commented 9 months ago
/*! \reimp  qt5 widget */
void QPushButton::keyPressEvent(QKeyEvent *e)
{
    Q_D(QPushButton);
    switch (e->key()) {
    case Qt::Key_Enter:
    case Qt::Key_Return:
        if (autoDefault() || d->defaultButton) {
            click();
            break;
        }
        Q_FALLTHROUGH();
    default:
        QAbstractButton::keyPressEvent(e);
    }
}
FeiWang1119 commented 9 months ago
bool QQuickAbstractButtonPrivate::acceptKeyClick(Qt::Key key) const
{
    const auto buttonPressKeys = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ButtonPressKeys).value<QList<Qt::Key>>();
    return buttonPressKeys.contains(key);
}

void QQuickAbstractButton::keyPressEvent(QKeyEvent *event)
{
    Q_D(QQuickAbstractButton);
    QQuickControl::keyPressEvent(event);
    if (d->acceptKeyClick(static_cast<Qt::Key>(event->key()))) {
        d->setPressPoint(d->centerPressPoint());
        setPressed(true);

        if (d->autoRepeat)
            d->startRepeatDelay();

        emit pressed();
        event->accept();
    }
}
deepin-ci-robot commented 9 months ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: FeiWang1119, kegechen

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files: - **[debian/deepin/OWNERS](https://github.com/linuxdeepin/qt5integration/blob/master/debian/deepin/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment