Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

FeiWang1119
Copy link

add the keys Return/Enter support in deepintheme

Issue: linuxdeepin/developer-center#5852

deepin-ci-robot added a commit to linuxdeepin/qt6integration that referenced this pull request Jan 3, 2024
Synchronize source files from linuxdeepin/qt5integration.

Source-pull-request: linuxdeepin/qt5integration#207
add the keys Return/Enter support in deepintheme

Issue: linuxdeepin/developer-center#5852
deepin-ci-robot added a commit to linuxdeepin/qt6integration that referenced this pull request Jan 3, 2024
Synchronize source files from linuxdeepin/qt5integration.

Source-pull-request: linuxdeepin/qt5integration#207
@FeiWang1119
Copy link
Author

FeiWang1119 commented Jan 3, 2024

/*! \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
Copy link
Author

FeiWang1119 commented Jan 3, 2024

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();
    }
}

@FeiWang1119 FeiWang1119 requested a review from zccrs January 4, 2024 01:45
@deepin-ci-robot
Copy link
Contributor

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

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@FeiWang1119 FeiWang1119 merged commit b877faf into linuxdeepin:master Jan 4, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants