@@ -190,33 +190,32 @@ namespace
190190 }
191191 }
192192
193- // The tooltip is a top-level QWidget with no parent (GotItTooltip's
194- // default parent is nullptr), so it cannot be found via
195- // dialog.findChild<>(). Dismissed/never-shown instances stay in
196- // topLevelWidgets() until their deleteLater() is actually processed, so
197- // only a visible one counts as "currently showing".
198- GotItTooltip* findVisibleTooltip ()
193+ // The tooltip is reparented (in showGotIt()) to the target's window,
194+ // i.e. somewhere under dialog once shown, so it's found via
195+ // dialog.findChildren<>() rather than topLevelWidgets(). Dismissed/
196+ // never-shown instances stay around until their deleteLater() is
197+ // actually processed, so only a visible one counts as "currently
198+ // showing".
199+ GotItTooltip* findVisibleTooltip (const QWidget& root)
199200 {
200- for (auto * widget : QApplication::topLevelWidgets ()) {
201- if (auto * tooltip = qobject_cast<GotItTooltip*>(widget);
202- tooltip != nullptr && tooltip->isVisible ()) {
203- return tooltip;
204- }
201+ for (auto * tooltip : root.findChildren <GotItTooltip*>()) {
202+ if (tooltip->isVisible ()) { return tooltip; }
205203 }
206204 return nullptr ;
207205 }
208206
209207 // One position's worth of the "show every position" loop, pulled out of
210208 // its TEST_CASE so that function's cognitive complexity (clang-tidy caps
211209 // it around 25) stays under the for-loop-plus-several-REQUIRE budget.
212- void showAndDismissGotIt (QComboBox& positionCombo, int index,
213- QPushButton& showButton, QPushButton& resetButton)
210+ void showAndDismissGotIt (const QWidget& root, QComboBox& positionCombo,
211+ int index, QPushButton& showButton,
212+ QPushButton& resetButton)
214213 {
215214 positionCombo.setCurrentIndex (index);
216215 QTest::mouseClick (&showButton, Qt::LeftButton);
217216 pump ();
218217
219- auto * tooltip = findVisibleTooltip ();
218+ auto * tooltip = findVisibleTooltip (root );
220219 REQUIRE (tooltip != nullptr );
221220 REQUIRE (tooltip->isVisible ());
222221
@@ -517,7 +516,8 @@ TEST_CASE("Show raises a GotItTooltip for every offered position",
517516 REQUIRE (positionCombo->count () == 3 );
518517
519518 for (int index = 0 ; index < positionCombo->count (); ++index) {
520- showAndDismissGotIt (*positionCombo, index, *showButton, *resetButton);
519+ showAndDismissGotIt (dialog, *positionCombo, index, *showButton,
520+ *resetButton);
521521 }
522522}
523523
@@ -548,40 +548,40 @@ TEST_CASE("The \"Got it\" section of a NotificationLauncherDialog",
548548 QTest::mouseClick (showButton, Qt::LeftButton);
549549 pump ();
550550
551- auto * tooltip = findVisibleTooltip ();
551+ auto * tooltip = findVisibleTooltip (dialog );
552552 REQUIRE (tooltip != nullptr );
553553 auto * gotItButton = tooltip->findChild <QPushButton*>();
554554 REQUIRE (gotItButton != nullptr );
555555 QTest::mouseClick (gotItButton, Qt::LeftButton);
556556 pump ();
557557
558- REQUIRE (findVisibleTooltip () == nullptr );
558+ REQUIRE (findVisibleTooltip (dialog ) == nullptr );
559559
560560 QTest::mouseClick (showButton, Qt::LeftButton);
561561 pump ();
562562
563- REQUIRE (findVisibleTooltip () == nullptr );
563+ REQUIRE (findVisibleTooltip (dialog ) == nullptr );
564564 }
565565
566566 SECTION (" Reset seen flag reshows the tooltip afterwards" )
567567 {
568568 QTest::mouseClick (showButton, Qt::LeftButton);
569569 pump ();
570570
571- auto * firstTooltip = findVisibleTooltip ();
571+ auto * firstTooltip = findVisibleTooltip (dialog );
572572 REQUIRE (firstTooltip != nullptr );
573573 auto * gotItButton = firstTooltip->findChild <QPushButton*>();
574574 REQUIRE (gotItButton != nullptr );
575575 QTest::mouseClick (gotItButton, Qt::LeftButton);
576576 pump ();
577577
578- REQUIRE (findVisibleTooltip () == nullptr );
578+ REQUIRE (findVisibleTooltip (dialog ) == nullptr );
579579
580580 QTest::mouseClick (resetButton, Qt::LeftButton);
581581 QTest::mouseClick (showButton, Qt::LeftButton);
582582 pump ();
583583
584- auto * secondTooltip = findVisibleTooltip ();
584+ auto * secondTooltip = findVisibleTooltip (dialog );
585585 REQUIRE (secondTooltip != nullptr );
586586 REQUIRE (secondTooltip->isVisible ());
587587
0 commit comments