summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-05-24 12:20:12 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-05-25 14:35:26 +0000
commitd2d63ed6794173e9aab2fec8a1a014a4c8f5e795 (patch)
tree10e0a9b3127a6c0119cefe246676ad4a79522127 /tests
parentca8047cfcd95f01bc689cf3ca04a46658a966056 (diff)
QLabel: always show the context menu created by the control
Amends e718818745e6db8df09ea55c4071e116f00851c9, after which a context menu was only shown if the format was rich text and there was a link at the position of the click. We always want to leave it up to the control to create a context menu, so only return early if there is no control. The control will then respect content at the position (i.e. link or not) and text interaction flags, and create the menu based on that. I.e. a rich text label with selectable text should still show "Select All" in the context menu, also if not clicking on a link. Add a test case to verify that the context menu event got accepted as expected, which indicates that the label showed a menu. Change-Id: Ib2b36286e4f1253d10489b5add83e8cdd7197a06 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> (cherry picked from commit 6a2b0291389fa32bd70a2c03119890275d5e0681) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
index 2775e2c683..9193a34c45 100644
--- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
+++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
@@ -77,6 +77,8 @@ private Q_SLOTS:
#ifndef QT_NO_CONTEXTMENU
void taskQTBUG_7902_contextMenuCrash();
+ void contextMenu_data();
+ void contextMenu();
#endif
void taskQTBUG_48157_dprPixmap();
@@ -561,6 +563,43 @@ void tst_QLabel::taskQTBUG_7902_contextMenuCrash()
QTest::qWait(350);
// No crash, it's allright.
}
+
+void tst_QLabel::contextMenu_data()
+{
+ QTest::addColumn<QString>("text");
+ QTest::addColumn<Qt::TextInteractionFlag>("interactionFlags");
+ QTest::addColumn<bool>("showsContextMenu");
+
+ QTest::addRow("Read-only") << "Plain Text"
+ << Qt::NoTextInteraction
+ << false;
+ QTest::addRow("Selectable") << "Plain Text"
+ << Qt::TextEditorInteraction
+ << true;
+ QTest::addRow("Link") << "<a href=\"nowhere\">Rich text with link</a>"
+ << Qt::TextBrowserInteraction
+ << true;
+ QTest::addRow("Rich text") << "<b>Rich text without link</b>"
+ << Qt::TextBrowserInteraction
+ << true;
+}
+
+void tst_QLabel::contextMenu()
+{
+ QFETCH(QString, text);
+ QFETCH(Qt::TextInteractionFlag, interactionFlags);
+ QFETCH(bool, showsContextMenu);
+
+ QLabel label(text);
+ label.setTextInteractionFlags(interactionFlags);
+ label.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&label));
+
+ const QPoint menuPosition = label.rect().center();
+ QContextMenuEvent cme(QContextMenuEvent::Mouse, menuPosition, label.mapToGlobal(menuPosition));
+ QApplication::sendEvent(&label, &cme);
+ QCOMPARE(cme.isAccepted(), showsContextMenu);
+}
#endif
void tst_QLabel::taskQTBUG_48157_dprPixmap()