From 8e40288f425d58c6422d8d942b5767f09a320833 Mon Sep 17 00:00:00 2001 From: Casper Jeukendrup <48658420+cbjeukendrup@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:48:02 +0200 Subject: [PATCH] Work around Qt 6.2.5+ rich text hover bug Relevant Qt commits: - broken in https://github.com/qt/qtdeclarative/commit/499828b855d125ac236917f6ed01d8f1e7d88505 - perhaps changed a bit in https://github.com/qt/qtdeclarative/commit/205e31df1674da5d9de78c4338d3221309086333, but not fixed Qt commit that seemed relevant at first, but didn't turn out to be: - https://github.com/qt/qtdeclarative/commit/cdc0e5cac27890a5ea0590dbdc7cf4c0f624dac2 --- .../UiComponents/internal/StyledMenuItem.qml | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/framework/uicomponents/qml/Muse/UiComponents/internal/StyledMenuItem.qml b/src/framework/uicomponents/qml/Muse/UiComponents/internal/StyledMenuItem.qml index 253eb14e5a412..31a9139a532e0 100644 --- a/src/framework/uicomponents/qml/Muse/UiComponents/internal/StyledMenuItem.qml +++ b/src/framework/uicomponents/qml/Muse/UiComponents/internal/StyledMenuItem.qml @@ -95,6 +95,22 @@ ListItemBlank { return text } + // https://github.com/musescore/MuseScore/pull/24644#issuecomment-2356235871 + // Since https://github.com/qt/qtdeclarative/commit/499828b855d125ac236917f6ed01d8f1e7d88505 + // (cherry-picked to Qt 6.2.5 as https://github.com/qt/qtdeclarative/commit/caf81fefbe3f5b8e2fb7892b40b4748db3230046) + // hover events are not propagated anymore between siblings, only to ancestors. + // For us, that means that they are not propagated anymore from the StyledTextLabel + // with `textFormat: Text.RichText` (which accepts hover events) to the MouseArea, + // which is not an ancestor of the StyledTextLabel. + // The fact that the StyledTextLabel accepts hover events cannot be changed from + // QML (there is no way to call `QQuickItem::setAcceptHoverEvents(false)`). + // Making the MouseArea an ancestor of the StyledTextLabel is not possible either, + // because the MouseArea is defined far away in FocusableControl (from which + // ListItemBlank inherits). + // As a workaround, we ensure that the MouseArea is on top of the StyledTextLabel, + // so that it takes precedence. + mouseArea.z: 1000 + QtObject { id: itemPrv @@ -198,11 +214,6 @@ ListItemBlank { text: itemPrv.titleWithMnemonicUnderline textFormat: Text.RichText - //! If the rich text format is set, then the component intercepts the hover state - // The hover state is required to open a submenu(see onHovered) - // So, let's turn off the mouse hovering over the component - enabled: false - opacity: root.enabled ? 1.0 : ui.theme.itemOpacityDisabled } StyledTextLabel {