Skip to content

Commit 8fb643f

Browse files
committed
Control: fix regression where hoverEnabled defaulted to false
Now (after 83d9084) that QQuickContentItem's parent is the content control rather than QQuickRootItem, we need to ensure that the control has the correct hoverEnabled value. If we don't do this (get the value from the style hints), it will use QQuickItem's default value of false and some controls won't be hoverable when they should be. Fixes: QTBUG-133886 Pick-to: 6.9 Change-Id: Ib0912acf7cdf513bf004837bc4ede970decf23d8 Reviewed-by: Tor Arne Vestbø <[email protected]>
1 parent 4bd5b31 commit 8fb643f

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/quicktemplates/qquickapplicationwindow.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,13 @@ void QQuickApplicationWindow::classBegin()
822822
// them.
823823
d->control = new QQuickControl(QQuickWindow::contentItem());
824824
d->control->setObjectName("ApplicationWindowContentControl");
825+
// Now that QQuickContentItem's parent is the content control rather
826+
// than QQuickRootItem, we need to ensure that the control has the
827+
// correct hoverEnabled value. If we don't do this (get the value
828+
// from the style hints), it will use QQuickItem's default value of false
829+
// and some controls won't be hoverable when they should be.
830+
QQuickControlPrivate::get(d->control)->updateHoverEnabled(
831+
QQuickControlPrivate::calcHoverEnabled(nullptr), false);
825832
auto *contentItem = new QQuickContentItem(this, d->control);
826833
// The content item can't be its own focus scope here, as that
827834
// will detach focus of items inside the content item from focus
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2025 The Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3+
4+
import QtQuick
5+
import QtQuick.Controls
6+
7+
ApplicationWindow {
8+
width: 400
9+
height: 400
10+
11+
property alias control: control
12+
13+
Control {
14+
id: control
15+
width: 100
16+
height: 100
17+
}
18+
}

tests/auto/quickcontrols/qquickcontrol/tst_qquickcontrol.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ private slots:
2727
void fractionalFontSize();
2828
void resizeBackgroundKeepsBindings();
2929
void hoverInMouseArea();
30+
void hoverEnabledDefault();
3031

3132
private:
3233
QScopedPointer<QPointingDevice> touchDevice;
@@ -137,6 +138,18 @@ void tst_QQuickControl::hoverInMouseArea()
137138
QVERIFY(textField->isHovered());
138139
}
139140

141+
void tst_QQuickControl::hoverEnabledDefault()
142+
{
143+
QQuickApplicationHelper helper(this, QStringLiteral("controlInApplicationWindow.qml"));
144+
QQuickWindow *window = helper.window;
145+
window->show();
146+
QVERIFY(QTest::qWaitForWindowExposed(window));
147+
148+
const auto *control = window->property("control").value<QQuickControl *>();
149+
QVERIFY(control);
150+
QCOMPARE(control->isHoverEnabled(), QGuiApplication::styleHints()->useHoverEffects());
151+
}
152+
140153
QTEST_QUICKCONTROLS_MAIN(tst_QQuickControl)
141154

142155
#include "tst_qquickcontrol.moc"

0 commit comments

Comments
 (0)