29 #include "../../../shared/highdpi.h"
47 #include <private/qwidget_p.h>
48 #include <private/qwidgetrepaintmanager_p.h>
49 #include <private/qapplication_p.h>
50 #include <private/qhighdpiscaling_p.h>
59 #include <QtCore/qoperatingsystemversion.h>
60 #include <QtGui/qpaintengine.h>
61 #include <QtGui/qpainterpath.h>
62 #include <QtGui/qbackingstore.h>
63 #include <QtGui/qguiapplication.h>
64 #include <QtGui/qpa/qplatformwindow.h>
65 #include <QtGui/qscreen.h>
72 #include <QtWidgets/QGraphicsView>
73 #include <QtWidgets/QGraphicsProxyWidget>
74 #include <QtGui/qwindow.h>
76 #include <QtWidgets/QDoubleSpinBox>
78 #if defined(Q_OS_MACOS)
82 #include <QtTest/QTest>
83 #include <QtTest/private/qtesthelpers_p.h>
88 # include <QtCore/qt_windows.h>
89 # include <QtGui/private/qguiapplication_p.h>
90 #include <qpa/qplatformnativeinterface.h>
91 #include <qpa/qplatformintegration.h>
95 static HWND winHandleOf(
const QWidget *
w)
100 return reinterpret_cast<HWND
>(
handle);
101 qWarning() <<
"Cannot obtain native handle for " <<
w;
105 # define Q_CHECK_PAINTEVENTS \
106 if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \
107 QSKIP("desktop is not visible, this test would fail");
110 # define Q_CHECK_PAINTEVENTS
114 #include <Security/AuthSession.h>
115 bool macHasAccessToWindowsServer()
118 SessionAttributeBits sessionInfo;
119 SessionGetInfo(callerSecuritySession, &
mySession, &sessionInfo);
120 return (sessionInfo & sessionHasGraphicAccess);
124 #if defined(Q_OS_WIN)
128 SystemParametersInfo(SPI_SETANIMATION, 0, &
animation, 0);
131 static inline bool windowsAnimationsEnabled()
133 ANIMATIONINFO
animation = {
sizeof(ANIMATIONINFO), 0 };
134 SystemParametersInfo(SPI_GETANIMATION, 0, &
animation, 0);
139 static inline bool windowsAnimationsEnabled() {
return false; }
147 return s.toLocal8Bit();
164 void addActionOverloads();
166 void fontPropagation();
167 void fontPropagation2();
168 void fontPropagation3();
169 void fontPropagationDynamic();
170 void palettePropagation();
171 void palettePropagation2();
172 void palettePropagationDynamic();
173 void enabledPropagation();
174 void ignoreKeyEventsWhenDisabled_QTBUG27417();
175 void properTabHandlingWhenDisabled_QTBUG27417();
176 #if QT_CONFIG(draganddrop)
177 void acceptDropsPropagation();
181 void visible_setWindowOpacity();
185 void mapFromAndTo_data();
187 void focusChainOnHide();
188 void focusChainOnReparent();
189 void defaultTabOrder();
190 void reverseTabOrder();
191 void tabOrderWithProxy();
192 void tabOrderWithProxyDisabled();
193 void tabOrderWithCompoundWidgets();
194 void tabOrderWithCompoundWidgetsNoFocusPolicy();
195 void tabOrderNoChange();
196 void tabOrderNoChange2();
197 void appFocusWidgetWithFocusProxyLater();
198 void appFocusWidgetWhenLosingFocusProxy();
199 void explicitTabOrderWithComplexWidget();
200 void explicitTabOrderWithSpinBox_QTBUG81097();
201 #if defined(Q_OS_WIN)
207 void showMaximized();
208 void showFullScreen();
209 void showMinimized();
210 void showMinimizedKeepsFocus();
212 void hideWhenFocusWidgetIsChild();
213 void normalGeometry();
215 void setGeometryHidden();
216 void windowOpacity();
220 void testContentsPropagation();
221 void saveRestoreGeometry();
222 void restoreVersion1Geometry_data();
223 void restoreVersion1Geometry();
229 void optimizedResizeMove();
230 void optimizedResize_topLevel();
234 void testDeletionInEventHandlers();
236 void childDeletesItsSibling();
238 void setMinimumSize();
239 void setMaximumSize();
242 void ensureCreated();
243 void createAndDestroy();
244 void winIdChangeEvent();
245 void persistentWinId();
246 void showNativeChild();
247 void closeAndShowNativeChild();
248 void closeAndShowWithNativeChild();
249 void transientParent();
250 void qobject_castInDestroyedSlot();
252 void showHideEvent_data();
253 void showHideEvent();
254 void showHideEventWhileMinimize();
255 void showHideChildrenWhileMinimize_QTBUG50589();
257 void lostUpdatesOnHide();
264 void scrollNativeChildren();
268 void setWindowGeometry_data();
269 void setWindowGeometry();
272 void windowMoveResize_data();
273 void windowMoveResize();
275 void moveChild_data();
277 void showAndMoveChild();
279 void subtractOpaqueSiblings();
281 #if defined (Q_OS_WIN)
282 void setGeometry_win();
286 void propagateLocale();
288 void multipleToplevelFocusCheck();
294 void testWindowIconChangeEventPropagation();
296 void minAndMaxSizeWithX11BypassWindowManagerHint();
297 void showHideShowX11();
298 void clean_qt_x11_enforce_cursor();
302 void renderChildFillsBackground();
303 void renderTargetOffset();
304 void renderInvisible();
305 void renderWithPainter();
306 void render_task188133();
307 void render_task211796();
308 void render_task217815();
309 void render_windowOpacity();
310 void render_systemClip();
311 void render_systemClip2_data();
312 void render_systemClip2();
313 void render_systemClip3_data();
314 void render_systemClip3();
315 void render_task252837();
316 void render_worldTransform();
318 void setContentsMargins();
320 void moveWindowInShowEvent_data();
321 void moveWindowInShowEvent();
323 void repaintWhenChildDeleted();
324 void hideOpaqueChildWhileHidden();
325 void updateWhileMinimized();
327 void nativeWindowPosition_data();
328 void nativeWindowPosition();
330 void adjustSize_data();
331 void updateGeometry();
332 void updateGeometry_data();
333 void sendUpdateRequestImmediately();
334 void doubleRepaint();
335 void resizeInPaintEvent();
336 void opaqueChildren();
338 void setMaskInResizeEvent();
339 void moveInResizeEvent();
341 #ifdef QT_BUILD_INTERNAL
342 void immediateRepaintAfterInvalidateBackingStore();
345 void effectiveWinId();
346 void effectiveWinId2();
348 void customDpiProperty();
350 void quitOnCloseAttribute();
353 #if defined (Q_OS_WIN)
355 void paintOnScreenPossible();
357 void reparentStaticWidget();
358 void QTBUG6883_reparentStaticWidget2();
360 void translucentWidget();
362 void setClearAndResizeMask();
365 void syntheticEnterLeave();
366 void enterLeaveOnWindowShowHide_data();
367 void enterLeaveOnWindowShowHide();
368 void taskQTBUG_4055_sendSyntheticEnterLeave();
370 void taskQTBUG_27643_enterEvents();
373 void initialPosForDontShowOnScreenWidgets();
374 void updateOnDestroyedSignal();
375 void toplevelLineEditFocus();
377 void focusWidget_task254563();
378 void rectOutsideCoordinatesLimit_task144779();
379 void setGraphicsEffect();
380 void render_graphicsEffect_data();
381 void render_graphicsEffect();
383 #ifdef QT_BUILD_INTERNAL
384 void destroyBackingStore();
387 void activateWindow();
389 void openModal_taskQTBUG_5804();
392 void focusProxyAndInputMethods();
393 #ifdef QT_BUILD_INTERNAL
394 void scrollWithoutBackingStore();
397 void taskQTBUG_7532_tabOrderWithFocusProxy();
398 void movedAndResizedAttributes();
401 void taskQTBUG_11373();
403 void taskQTBUG_17333_ResizeInfiniteRecursion();
405 void nativeChildFocus();
410 void touchEventSynthesizedMouseEvent();
411 void touchUpdateOnNewTouch();
413 void touchEventsForGesturePendingWidgets();
415 void styleSheetPropagation();
417 void destroyedSignal();
419 void keyboardModifiers();
420 void mouseDoubleClickBubbling_QTBUG29680();
421 void largerThanScreen_QTBUG30142();
423 void resizeStaticContentsChildWidget_QTBUG35282();
425 void qmlSetParentHelper();
427 void testForOutsideWSRangeFlag();
429 void tabletTracking();
432 void closeWithChildWindow();
434 void winIdAfterClose();
435 void receivesLanguageChangeEvent();
436 void receivesApplicationFontChangeEvent();
437 void receivesApplicationPaletteChangeEvent();
438 void deleteWindowInCloseEvent();
441 void setParentChangesFocus_data();
442 void setParentChangesFocus();
444 void activateWhileModalHidden();
447 void showFullscreenAndroid();
452 QSize m_testWidgetSize;
453 QPoint m_availableTopLeft;
454 QPoint m_safeCursorPos;
455 const bool m_windowsAnimationsEnabled;
461 void tst_QWidget::getSetCheck()
464 QWidget child1(&obj1);
468 obj1.setStyle(var1.data());
470 obj1.setStyle(
nullptr);
471 QVERIFY(var1.data() != obj1.style());
472 QVERIFY(obj1.style() !=
nullptr);
474 const QRegularExpression negativeNotPossible(
u"^.*Negative sizes \\(.*\\) are not possible$"_qs);
475 const QRegularExpression largestAllowedSize(
u"^.*The largest allowed size is \\(.*\\)$"_qs);
478 obj1.setMinimumWidth(0);
481 obj1.setMinimumWidth(INT_MIN);
484 obj1.setMinimumWidth(INT_MAX);
486 child1.setMinimumWidth(0);
489 child1.setMinimumWidth(INT_MIN);
492 child1.setMinimumWidth(INT_MAX);
497 obj1.setMinimumHeight(0);
500 obj1.setMinimumHeight(INT_MIN);
503 obj1.setMinimumHeight(INT_MAX);
505 child1.setMinimumHeight(0);
506 QCOMPARE(child1.minimumHeight(), 0);
508 child1.setMinimumHeight(INT_MIN);
509 QCOMPARE(child1.minimumHeight(), 0);
511 child1.setMinimumHeight(INT_MAX);
516 obj1.setMaximumWidth(0);
519 obj1.setMaximumWidth(INT_MIN);
522 obj1.setMaximumWidth(INT_MAX);
527 obj1.setMaximumHeight(0);
530 obj1.setMaximumHeight(INT_MIN);
533 obj1.setMaximumHeight(INT_MAX);
537 obj1.setMinimumWidth(0);
538 obj1.setMinimumHeight(0);
545 obj1.setPalette(var6);
547 obj1.setPalette(QPalette());
548 QCOMPARE(QPalette(), obj1.palette());
555 obj1.setFont(QFont());
560 obj1.setWindowOpacity(0.0);
561 QCOMPARE(0.0, obj1.windowOpacity());
562 obj1.setWindowOpacity(1.1);
563 QCOMPARE(1.0, obj1.windowOpacity());
569 obj1.setFocusProxy(var9.data());
570 QCOMPARE(var9.data(), obj1.focusProxy());
571 obj1.setFocusProxy(
nullptr);
572 QCOMPARE(
nullptr, obj1.focusProxy());
578 QRect var10(10, 10, 100, 100);
579 obj1.setGeometry(var10);
581 qDebug() << obj1.geometry();
583 obj1.setGeometry(QRect(0,0,0,0));
584 qDebug() << obj1.geometry();
585 QCOMPARE(QRect(0,0,0,0), obj1.geometry());
590 obj1.setLayout(var11);
593 obj1.setLayout(
nullptr);
600 obj1.setAcceptDrops(
false);
601 QCOMPARE(
false, obj1.acceptDrops());
602 obj1.setAcceptDrops(
true);
607 obj1.setAutoFillBackground(
false);
608 QCOMPARE(
false, obj1.autoFillBackground());
609 obj1.setAutoFillBackground(
true);
610 QCOMPARE(
true, obj1.autoFillBackground());
613 #if defined (Q_OS_WIN)
615 const HWND
handle =
reinterpret_cast<HWND
>(obj1.winId());
622 , m_safeCursorPos(0, 0)
623 , m_windowsAnimationsEnabled(windowsAnimationsEnabled())
627 if (m_windowsAnimationsEnabled)
631 font.setPointSize(42);
640 qputenv(
"QT_WAYLAND_DISABLE_WINDOWDECORATION",
"1");
645 if (m_windowsAnimationsEnabled)
648 delete m_touchScreen;
658 m_availableTopLeft = availableGeometry.topLeft();
663 m_safeCursorPos = availableGeometry.bottomRight() - QPoint(40, 40);
665 if (screenWidth > 2000)
666 width = 100 * ((screenWidth + 500) / 1000);
675 template <
typename T>
678 operator const T()
const {
return t; }
679 operator T() {
return t; }
685 void tst_QWidget::addActionOverloads()
697 const auto check = [&](
auto &...args) {
698 w.addAction(
args...);
706 w.addAction(
args..., [&](
bool b) {
w.setEnabled(
b); });
707 w.addAction(
args..., &
w, [&](
bool b) {
w.setEnabled(
b); });
718 const auto check1 = [&](
auto &
arg,
auto &...args) {
720 check(std::as_const(
arg),
args...);
722 const auto check2 = [&](
auto &
arg1,
auto &
arg2,
auto &...args) {
727 const auto check3 = [&](
auto &
arg1,
auto &
arg2,
auto &
arg3) {
734 #ifndef QT_NO_SHORTCUT
736 check2(
text, keySequence);
737 check3(icon,
text, keySequence);
741 void tst_QWidget::fontPropagation()
744 testWidget->resize(m_testWidgetSize);
745 testWidget->setWindowTitle(__FUNCTION__);
746 centerOnScreen(testWidget.data());
749 QFont
font = testWidget->font();
754 font.setBold(
true );
755 testWidget->setFont(
font );
759 QFont newFont =
font;
760 newFont.setItalic(
true );
761 childWidget->setFont( newFont );
764 QCOMPARE( newFont, grandChildWidget->font() );
766 font.setUnderline(
true );
767 testWidget->setFont(
font );
771 newFont.setUnderline(
true );
773 QCOMPARE( newFont, childWidget->font() );
774 QCOMPARE( newFont, grandChildWidget->font() );
777 font = testWidget->font();
778 font.setPointSize(
font.pointSize() + 2);
779 testWidget->setFont(
font);
786 four->setParent(
three);
787 four->move(QPoint(0,0));
789 font.setPointSize(
font.pointSize() + 2);
790 testWidget->setFont(
font);
792 QCOMPARE(testWidget->font(), one->font());
803 font.setPointSize(
font.pointSize() + 2);
815 font.setPointSize(
font.pointSize() + 2);
825 font.setPointSize(
font.pointSize() + 2);
833 font.setPointSize(
font.pointSize() + 2);
846 void tst_QWidget::fontPropagation2()
856 root->setWindowTitle(root->objectName());
857 root->resize(200, 200);
871 QCOMPARE(child2->font().pointSize(), 42);
872 QVERIFY(child2->font().bold());
873 QCOMPARE(child3->font().pointSize(), 42);
874 QVERIFY(child3->font().bold());
875 QCOMPARE(child4->font().pointSize(), 42);
876 QVERIFY(child4->font().bold());
877 QCOMPARE(child5->font().pointSize(), 42);
878 QVERIFY(child5->font().bold());
882 font.setPointSize(15);
883 child0->setFont(
font);
885 unboldFont.setBold(
false);
886 child4->setFont(unboldFont);
890 QCOMPARE(child0->font().pointSize(), 15);
891 QVERIFY(!child0->font().bold());
892 QCOMPARE(child1->font().pointSize(), 15);
893 QVERIFY(!child1->font().bold());
894 QCOMPARE(child2->font().pointSize(), 15);
895 QVERIFY(child2->font().bold());
896 QCOMPARE(child3->font().pointSize(), 15);
897 QVERIFY(child3->font().bold());
898 QCOMPARE(child4->font().pointSize(), 15);
899 QVERIFY(!child4->font().bold());
900 QCOMPARE(child5->font().pointSize(), 15);
901 QVERIFY(!child5->font().bold());
906 QFont italicSizeFont;
907 italicSizeFont.setItalic(
true);
908 italicSizeFont.setPointSize(33);
913 QCOMPARE(child0->font().pointSize(), 15);
914 QVERIFY(!child0->font().bold());
915 QVERIFY(!child0->font().italic());
916 QCOMPARE(child1->font().pointSize(), 15);
917 QVERIFY(!child1->font().bold());
918 QVERIFY(!child1->font().italic());
919 QCOMPARE(child2->font().pointSize(), 15);
920 QVERIFY(!child2->font().bold());
921 QVERIFY(child2->font().italic());
922 QCOMPARE(child3->font().pointSize(), 15);
923 QVERIFY(!child3->font().bold());
924 QVERIFY(child3->font().italic());
925 QCOMPARE(child4->font().pointSize(), 15);
926 QVERIFY(!child4->font().bold());
927 QVERIFY(child4->font().italic());
928 QCOMPARE(child5->font().pointSize(), 15);
929 QVERIFY(!child5->font().bold());
930 QVERIFY(child5->font().italic());
933 void tst_QWidget::fontPropagation3()
937 parent.setFont(QFont(
"Monospace", 9));
950 void tst_QWidget::fontPropagationDynamic()
954 themedFont.setBold(
true);
955 themedFont.setPointSize(42);
961 const QFont defaultFont =
parent.font();
962 QFont appFont = defaultFont;
963 appFont.setPointSize(72);
966 QVERIFY(themedFont != defaultFont);
967 QVERIFY(themedFont != appFont);
971 QCOMPARE(firstChild.font().pointSize(), appFont.pointSize());
975 QCOMPARE(secondChild.font().pointSize(), appFont.pointSize());
977 QCOMPARE(thirdChild.font().pointSize(), defaultFont.pointSize());
978 thirdChild.setParent(&
parent);
979 QCOMPARE(thirdChild.font().pointSize(), appFont.pointSize());
983 themedChild.ensurePolished();
984 QCOMPARE(themedChild.font().pointSize(), themedFont.pointSize());
985 QCOMPARE(themedChild.font().bold(), themedFont.bold());
986 themedChild.setParent(&
parent);
987 QCOMPARE(themedChild.font().pointSize(), appFont.pointSize());
988 QCOMPARE(themedChild.font().bold(), themedFont.bold());
992 themedGrandChild.setParent(&themedChild);
993 QCOMPARE(themedGrandChild.font().pointSize(), appFont.pointSize());
994 QCOMPARE(themedGrandChild.font().bold(), themedFont.bold());
997 QFont childFont = defaultFont;
998 childFont.setPointSize(9);
1000 modifiedChild.setFont(childFont);
1001 modifiedChild.setParent(&
parent);
1002 QCOMPARE(modifiedChild.font().pointSize(), childFont.pointSize());
1005 void tst_QWidget::palettePropagation()
1008 testWidget->resize(m_testWidgetSize);
1009 testWidget->setWindowTitle(__FUNCTION__);
1010 centerOnScreen(testWidget.data());
1014 QPalette
palette = testWidget->palette();
1016 childWidget->show();
1020 testWidget->setPalette(
palette );
1024 QPalette newPalette =
palette;
1026 childWidget->setPalette( newPalette );
1029 QCOMPARE( newPalette, grandChildWidget->palette() );
1032 testWidget->setPalette(
palette );
1038 QCOMPARE( newPalette, childWidget->palette() );
1039 QCOMPARE( newPalette, grandChildWidget->palette() );
1042 void tst_QWidget::palettePropagation2()
1045 QSKIP(
"Wayland: This fails. Figure out why.");
1055 root->setWindowTitle(root->objectName());
1056 root->resize(200, 200);
1068 QColor sysPalText(21, 22, 23);
1069 QColor sysPalToolTipBase(12, 13, 14);
1070 QColor overridePalText(42, 43, 44);
1071 QColor overridePalToolTipBase(45, 46, 47);
1072 QColor sysPalButton(99, 98, 97);
1077 QCOMPARE(child0->palette(), appPal);
1078 QCOMPARE(child1->palette(), appPal);
1093 QPalette textPalette;
1095 child0->setPalette(textPalette);
1096 QPalette toolTipPalette;
1098 child4->setPalette(toolTipPalette);
1123 QPalette buttonPalette;
1154 void tst_QWidget::palettePropagationDynamic()
1157 QPalette themedPalette;
1165 const QPalette defaultPalette =
parent.palette();
1166 QPalette appPalette = defaultPalette;
1167 const QColor appColor(1, 2, 3);
1171 QVERIFY(themedPalette != defaultPalette);
1172 QVERIFY(themedPalette != appPalette);
1175 parent.setPalette(appPalette);
1183 thirdChild.setParent(&
parent);
1188 themedChild.ensurePolished();
1191 themedChild.setParent(&
parent);
1197 themedGrandChild.setParent(&themedChild);
1202 QPalette childPalette = defaultPalette;
1205 modifiedChild.setPalette(childPalette);
1206 modifiedChild.setParent(&
parent);
1211 void tst_QWidget::enabledPropagation()
1214 testWidget->resize(m_testWidgetSize);
1215 testWidget->setWindowTitle(__FUNCTION__);
1216 centerOnScreen(testWidget.data());
1220 childWidget->show();
1221 QVERIFY( testWidget->isEnabled() );
1222 QVERIFY( childWidget->isEnabled() );
1224 testWidget->setEnabled(
false );
1225 QVERIFY( !testWidget->isEnabled() );
1226 QVERIFY( !childWidget->isEnabled() );
1228 testWidget->setDisabled(
false );
1229 QVERIFY( testWidget->isEnabled() );
1230 QVERIFY( childWidget->isEnabled() );
1233 QVERIFY( grandChildWidget->isEnabled() );
1235 testWidget->setDisabled(
true );
1236 QVERIFY( !testWidget->isEnabled() );
1237 QVERIFY( !childWidget->isEnabled() );
1238 QVERIFY( !grandChildWidget->isEnabled() );
1240 grandChildWidget->setEnabled(
false );
1241 testWidget->setEnabled(
true );
1242 QVERIFY( testWidget->isEnabled() );
1243 QVERIFY( childWidget->isEnabled() );
1244 QVERIFY( !grandChildWidget->isEnabled() );
1246 grandChildWidget->setEnabled(
true );
1247 testWidget->setEnabled(
false );
1248 childWidget->setDisabled(
true );
1249 testWidget->setEnabled(
true );
1250 QVERIFY( testWidget->isEnabled() );
1251 QVERIFY( !childWidget->isEnabled() );
1252 QVERIFY( !grandChildWidget->isEnabled() );
1255 void tst_QWidget::ignoreKeyEventsWhenDisabled_QTBUG27417()
1269 void tst_QWidget::properTabHandlingWhenDisabled_QTBUG27417()
1272 QSKIP(
"Wayland: This fails. Figure out why.");
1277 centerOnScreen(&widget);
1278 QVBoxLayout *
layout =
new QVBoxLayout();
1282 layout->addWidget(lineEdit2);
1284 layout->addWidget(lineEdit3);
1304 #if QT_CONFIG(draganddrop)
1305 void tst_QWidget::acceptDropsPropagation()
1308 testWidget->resize(m_testWidgetSize);
1309 testWidget->setWindowTitle(__FUNCTION__);
1310 centerOnScreen(testWidget.data());
1314 childWidget->show();
1315 QVERIFY(!testWidget->acceptDrops());
1316 QVERIFY(!childWidget->acceptDrops());
1318 testWidget->setAcceptDrops(
true);
1319 QVERIFY(testWidget->acceptDrops());
1320 QVERIFY(!childWidget->acceptDrops());
1323 testWidget->setAcceptDrops(
false);
1324 QVERIFY(!testWidget->acceptDrops());
1325 QVERIFY(!childWidget->acceptDrops());
1329 QVERIFY(!grandChildWidget->acceptDrops());
1332 testWidget->setAcceptDrops(
true);
1333 QVERIFY(testWidget->acceptDrops());
1334 QVERIFY(!childWidget->acceptDrops());
1336 QVERIFY(!grandChildWidget->acceptDrops());
1339 grandChildWidget->setAcceptDrops(
true);
1340 testWidget->setAcceptDrops(
false);
1341 QVERIFY(!testWidget->acceptDrops());
1342 QVERIFY(!childWidget->acceptDrops());
1343 QVERIFY(grandChildWidget->acceptDrops());
1346 grandChildWidget->setAcceptDrops(
false);
1348 testWidget->setAcceptDrops(
true);
1349 childWidget->setAcceptDrops(
true);
1350 testWidget->setAcceptDrops(
false);
1351 QVERIFY(!testWidget->acceptDrops());
1352 QVERIFY(childWidget->acceptDrops());
1353 QVERIFY(!grandChildWidget->acceptDrops());
1358 void tst_QWidget::isEnabledTo()
1361 testWidget.resize(m_testWidgetSize);
1362 testWidget.setWindowTitle(__FUNCTION__);
1363 centerOnScreen(&testWidget);
1368 QVERIFY( childWidget->isEnabledTo( &testWidget ) );
1369 QVERIFY( grandChildWidget->isEnabledTo( &testWidget ) );
1371 childWidget->setEnabled(
false );
1372 QVERIFY( !childWidget->isEnabledTo( &testWidget ) );
1373 QVERIFY( grandChildWidget->isEnabledTo( childWidget ) );
1374 QVERIFY( !grandChildWidget->isEnabledTo( &testWidget ) );
1377 testWidget.setEnabled(
false);
1378 QVERIFY(!childDialog->isEnabled());
1379 QVERIFY(childDialog->isEnabledTo(
nullptr));
1382 void tst_QWidget::visible()
1387 testWidget->resize(m_testWidgetSize);
1388 testWidget->setWindowTitle(__FUNCTION__);
1389 centerOnScreen(testWidget.data());
1390 QVERIFY( !testWidget->isVisible() );
1392 QVERIFY( !childWidget->isVisible() );
1395 QVERIFY(testWidget->screen());
1396 QVERIFY( testWidget->isVisible() );
1397 QVERIFY( childWidget->isVisible() );
1400 QVERIFY( !grandChildWidget->isVisible() );
1401 grandChildWidget->show();
1402 QVERIFY( grandChildWidget->isVisible() );
1404 grandChildWidget->hide();
1407 QVERIFY( !grandChildWidget->isVisible() );
1408 QVERIFY( testWidget->isVisible() );
1409 QVERIFY( childWidget->isVisible() );
1411 grandChildWidget->show();
1412 childWidget->hide();
1415 QVERIFY( testWidget->isVisible() );
1416 QVERIFY( !childWidget->isVisible() );
1417 QVERIFY( !grandChildWidget->isVisible() );
1419 grandChildWidget->show();
1420 QVERIFY( !grandChildWidget->isVisible() );
1423 void tst_QWidget::setLocale()
1436 QCOMPARE(child1.locale(), QLocale());
1446 child1.unsetLocale();
1451 QCOMPARE(child2.locale(), QLocale());
1452 child2.setParent(&
w);
1456 void tst_QWidget::propagateLocale()
1483 void tst_QWidget::visible_setWindowOpacity()
1486 testWidget->resize(m_testWidgetSize);
1487 testWidget->setWindowTitle(__FUNCTION__);
1488 centerOnScreen(testWidget.data());
1489 testWidget->winId();
1491 QVERIFY( !testWidget->isVisible() );
1492 testWidget->setWindowOpacity(0.5);
1493 #if defined(Q_OS_WIN)
1494 QVERIFY(!::IsWindowVisible(winHandleOf(testWidget.data())));
1496 testWidget->setWindowOpacity(1.0);
1499 void tst_QWidget::isVisibleTo()
1504 testWidget.resize(m_testWidgetSize);
1505 testWidget.setWindowTitle(__FUNCTION__);
1506 centerOnScreen(&testWidget);
1509 QVERIFY( childWidget->isVisibleTo( &testWidget ) );
1510 childWidget->hide();
1511 QVERIFY( !childWidget->isVisibleTo( &testWidget ) );
1514 QVERIFY( !grandChildWidget->isVisibleTo( &testWidget ) );
1515 QVERIFY( grandChildWidget->isVisibleTo( childWidget ) );
1518 childWidget->show();
1520 QVERIFY( childWidget->isVisibleTo( &testWidget ) );
1521 grandChildWidget->hide();
1522 QVERIFY( !grandChildWidget->isVisibleTo( childWidget ) );
1523 QVERIFY( !grandChildWidget->isVisibleTo( &testWidget ) );
1526 void tst_QWidget::isHidden()
1531 testWidget->resize(m_testWidgetSize);
1532 testWidget->setWindowTitle(__FUNCTION__);
1533 centerOnScreen(testWidget.data());
1535 QVERIFY( testWidget->isHidden() );
1537 QVERIFY( !childWidget->isHidden() );
1540 QVERIFY( !testWidget->isHidden() );
1541 QVERIFY( !childWidget->isHidden() );
1544 QVERIFY( grandChildWidget->isHidden() );
1545 grandChildWidget->show();
1546 QVERIFY( !grandChildWidget->isHidden() );
1548 grandChildWidget->hide();
1551 QVERIFY( grandChildWidget->isHidden() );
1552 QVERIFY( !testWidget->isHidden() );
1553 QVERIFY( !childWidget->isHidden() );
1555 grandChildWidget->show();
1556 childWidget->hide();
1559 QVERIFY( !testWidget->isHidden() );
1560 QVERIFY( childWidget->isHidden() );
1561 QVERIFY( !grandChildWidget->isHidden() );
1563 grandChildWidget->show();
1564 QVERIFY( !grandChildWidget->isHidden() );
1567 void tst_QWidget::fonts()
1570 testWidget.resize(m_testWidgetSize);
1571 testWidget.setWindowTitle(__FUNCTION__);
1572 centerOnScreen(&testWidget);
1578 QFont originalFont = cleanTestWidget->font();
1581 cleanTestWidget->setFont(QFont());
1584 QFont newFont(
"times", 18 );
1585 cleanTestWidget->setFont( newFont );
1586 newFont = newFont.resolve( testWidget.font() );
1589 QVERIFY2( cleanTestWidget->font() == newFont,
1590 msgComparisonFailed(cleanTestWidget->font(),
"==", newFont));
1592 cleanTestWidget->setFont(QFont());
1594 QVERIFY2( cleanTestWidget->font() == originalFont,
1595 msgComparisonFailed(cleanTestWidget->font(),
"==", originalFont));
1598 void tst_QWidget::mapFromAndTo_data()
1600 QTest::addColumn<bool>(
"windowHidden");
1601 QTest::addColumn<bool>(
"subWindow1Hidden");
1602 QTest::addColumn<bool>(
"subWindow2Hidden");
1603 QTest::addColumn<bool>(
"subSubWindowHidden");
1604 QTest::addColumn<bool>(
"windowMinimized");
1605 QTest::addColumn<bool>(
"subWindow1Minimized");
1607 QTest::newRow(
"window 1 sub1 1 sub2 1 subsub 1") <<
false <<
false <<
false <<
false <<
false <<
false;
1608 QTest::newRow(
"window 0 sub1 1 sub2 1 subsub 1") <<
true <<
false <<
false <<
false <<
false <<
false;
1609 QTest::newRow(
"window 1 sub1 0 sub2 1 subsub 1") <<
false <<
true <<
false <<
false <<
false <<
false;
1610 QTest::newRow(
"window 0 sub1 0 sub2 1 subsub 1") <<
true <<
true <<
false <<
false <<
false <<
false;
1611 QTest::newRow(
"window 1 sub1 1 sub2 0 subsub 1") <<
false <<
false <<
true <<
false <<
false <<
false;
1612 QTest::newRow(
"window 0 sub1 1 sub2 0 subsub 1") <<
true <<
false <<
true <<
false <<
false <<
false;
1613 QTest::newRow(
"window 1 sub1 0 sub2 0 subsub 1") <<
false <<
true <<
true <<
false <<
false <<
false;
1614 QTest::newRow(
"window 0 sub1 0 sub2 0 subsub 1") <<
true <<
true <<
true <<
false <<
false <<
false;
1615 QTest::newRow(
"window 1 sub1 1 sub2 1 subsub 0") <<
false <<
false <<
false <<
true <<
false <<
false;
1616 QTest::newRow(
"window 0 sub1 1 sub2 1 subsub 0") <<
true <<
false <<
false <<
true <<
false <<
false;
1617 QTest::newRow(
"window 1 sub1 0 sub2 1 subsub 0") <<
false <<
true <<
false <<
true <<
false <<
false;
1618 QTest::newRow(
"window 0 sub1 0 sub2 1 subsub 0") <<
true <<
true <<
false <<
true <<
false <<
false;
1619 QTest::newRow(
"window 1 sub1 1 sub2 0 subsub 0") <<
false <<
false <<
true <<
true <<
false <<
false;
1620 QTest::newRow(
"window 0 sub1 1 sub2 0 subsub 0") <<
true <<
false <<
true <<
true <<
false <<
false;
1621 QTest::newRow(
"window 1 sub1 0 sub2 0 subsub 0") <<
false <<
true <<
true <<
true <<
false <<
false;
1622 QTest::newRow(
"window 0 sub1 0 sub2 0 subsub 0") <<
true <<
true <<
true <<
true <<
false <<
false;
1623 QTest::newRow(
"window 1 sub1 1 sub2 1 subsub 1 windowMinimized") <<
false <<
false <<
false <<
false <<
true <<
false;
1624 QTest::newRow(
"window 0 sub1 1 sub2 1 subsub 1 windowMinimized") <<
true <<
false <<
false <<
false <<
true <<
false;
1625 QTest::newRow(
"window 1 sub1 0 sub2 1 subsub 1 windowMinimized") <<
false <<
true <<
false <<
false <<
true <<
false;
1626 QTest::newRow(
"window 0 sub1 0 sub2 1 subsub 1 windowMinimized") <<
true <<
true <<
false <<
false <<
true <<
false;
1627 QTest::newRow(
"window 1 sub1 1 sub2 0 subsub 1 windowMinimized") <<
false <<
false <<
true <<
false <<
true <<
false;
1628 QTest::newRow(
"window 0 sub1 1 sub2 0 subsub 1 windowMinimized") <<
true <<
false <<
true <<
false <<
true <<
false;
1629 QTest::newRow(
"window 1 sub1 0 sub2 0 subsub 1 windowMinimized") <<
false <<
true <<
true <<
false <<
true <<
false;
1630 QTest::newRow(
"window 0 sub1 0 sub2 0 subsub 1 windowMinimized") <<
true <<
true <<
true <<
false <<
true <<
false;
1631 QTest::newRow(
"window 1 sub1 1 sub2 1 subsub 0 windowMinimized") <<
false <<
false <<
false <<
true <<
true <<
false;
1632 QTest::newRow(
"window 0 sub1 1 sub2 1 subsub 0 windowMinimized") <<
true <<
false <<
false <<
true <<
true <<
false;
1633 QTest::newRow(
"window 1 sub1 0 sub2 1 subsub 0 windowMinimized") <<
false <<
true <<
false <<
true <<
true <<
false;
1634 QTest::newRow(
"window 0 sub1 0 sub2 1 subsub 0 windowMinimized") <<
true <<
true <<
false <<
true <<
true <<
false;
1635 QTest::newRow(
"window 1 sub1 1 sub2 0 subsub 0 windowMinimized") <<
false <<
false <<
true <<
true <<
true <<
false;
1636 QTest::newRow(
"window 0 sub1 1 sub2 0 subsub 0 windowMinimized") <<
true <<
false <<
true <<
true <<
true <<
false;
1637 QTest::newRow(
"window 1 sub1 0 sub2 0 subsub 0 windowMinimized") <<
false <<
true <<
true <<
true <<
true <<
false;
1638 QTest::newRow(
"window 0 sub1 0 sub2 0 subsub 0 windowMinimized") <<
true <<
true <<
true <<
true <<
true <<
false;
1639 QTest::newRow(
"window 1 sub1 1 sub2 1 subsub 1 subWindow1Minimized") <<
false <<
false <<
false <<
false <<
false <<
true;
1640 QTest::newRow(
"window 0 sub1 1 sub2 1 subsub 1 subWindow1Minimized") <<
true <<
false <<
false <<
false <<
false <<
true;
1641 QTest::newRow(
"window 1 sub1 0 sub2 1 subsub 1 subWindow1Minimized") <<
false <<
true <<
false <<
false <<
false <<
true;
1642 QTest::newRow(
"window 0 sub1 0 sub2 1 subsub 1 subWindow1Minimized") <<
true <<
true <<
false <<
false <<
false <<
true;
1643 QTest::newRow(
"window 1 sub1 1 sub2 0 subsub 1 subWindow1Minimized") <<
false <<
false <<
true <<
false <<
false <<
true;
1644 QTest::newRow(
"window 0 sub1 1 sub2 0 subsub 1 subWindow1Minimized") <<
true <<
false <<
true <<
false <<
false <<
true;
1645 QTest::newRow(
"window 1 sub1 0 sub2 0 subsub 1 subWindow1Minimized") <<
false <<
true <<
true <<
false <<
false <<
true;
1646 QTest::newRow(
"window 0 sub1 0 sub2 0 subsub 1 subWindow1Minimized") <<
true <<
true <<
true <<
false <<
false <<
true;
1647 QTest::newRow(
"window 1 sub1 1 sub2 1 subsub 0 subWindow1Minimized") <<
false <<
false <<
false <<
true <<
false <<
true;
1648 QTest::newRow(
"window 0 sub1 1 sub2 1 subsub 0 subWindow1Minimized") <<
true <<
false <<
false <<
true <<
false <<
true;
1649 QTest::newRow(
"window 1 sub1 0 sub2 1 subsub 0 subWindow1Minimized") <<
false <<
true <<
false <<
true <<
false <<
true;
1650 QTest::newRow(
"window 0 sub1 0 sub2 1 subsub 0 subWindow1Minimized") <<
true <<
true <<
false <<
true <<
false <<
true;
1651 QTest::newRow(
"window 1 sub1 1 sub2 0 subsub 0 subWindow1Minimized") <<
false <<
false <<
true <<
true <<
false <<
true;
1652 QTest::newRow(
"window 0 sub1 1 sub2 0 subsub 0 subWindow1Minimized") <<
true <<
false <<
true <<
true <<
false <<
true;
1653 QTest::newRow(
"window 1 sub1 0 sub2 0 subsub 0 subWindow1Minimized") <<
false <<
true <<
true <<
true <<
false <<
true;
1654 QTest::newRow(
"window 0 sub1 0 sub2 0 subsub 0 subWindow1Minimized") <<
true <<
true <<
true <<
true <<
false <<
true;
1659 void tst_QWidget::mapFromAndTo()
1661 QFETCH(
bool, windowHidden);
1662 QFETCH(
bool, subWindow1Hidden);
1663 QFETCH(
bool, subWindow2Hidden);
1664 QFETCH(
bool, subSubWindowHidden);
1665 QFETCH(
bool, windowMinimized);
1666 QFETCH(
bool, subWindow1Minimized);
1678 window.setGeometry(100, 100, 100, 100);
1679 subWindow1->setGeometry(50, 50, 100, 100);
1680 subWindow2->setGeometry(75, 75, 100, 100);
1681 subSubWindow->setGeometry(10, 10, 10, 10);
1683 #if !defined(Q_OS_QNX)
1685 if (windowMinimized) {
1686 if (!windowHidden) {
1691 window.setVisible(!windowHidden);
1693 if (subWindow1Minimized) {
1695 subWindow1->showMinimized();
1696 QVERIFY(subWindow1->isMinimized());
1698 subWindow1->setVisible(!subWindow1Hidden);
1707 subWindow2->setVisible(!subWindow2Hidden);
1708 subSubWindow->setVisible(!subSubWindowHidden);
1716 QCOMPARE(
window.mapToGlobal(QPoint(100, 100)), QPoint(200, 200));
1719 QCOMPARE(
window.mapToGlobal(QPoint(110, 100)), QPoint(210, 200));
1720 QCOMPARE(
window.mapToGlobal(QPoint(100, 110)), QPoint(200, 210));
1726 QCOMPARE(
window.mapFromGlobal(QPoint(200, 200)), QPoint(100, 100));
1729 QCOMPARE(
window.mapFromGlobal(QPoint(210, 200)), QPoint(110, 100));
1730 QCOMPARE(
window.mapFromGlobal(QPoint(200, 210)), QPoint(100, 110));
1736 QCOMPARE(
window.mapToParent(QPoint(100, 100)), QPoint(200, 200));
1737 QCOMPARE(
window.mapToParent(QPoint(110, 100)), QPoint(210, 200));
1738 QCOMPARE(
window.mapToParent(QPoint(100, 110)), QPoint(200, 210));
1744 QCOMPARE(
window.mapFromParent(QPoint(200, 200)), QPoint(100, 100));
1745 QCOMPARE(
window.mapFromParent(QPoint(210, 200)), QPoint(110, 100));
1746 QCOMPARE(
window.mapFromParent(QPoint(200, 210)), QPoint(100, 110));
1749 QCOMPARE(subWindow1->mapToGlobal(QPoint(0, 0)), QPoint(150, 150));
1750 QCOMPARE(subWindow1->mapToGlobal(QPoint(10, 0)), QPoint(160, 150));
1751 QCOMPARE(subWindow1->mapToGlobal(QPoint(0, 10)), QPoint(150, 160));
1752 QCOMPARE(subWindow1->mapToGlobal(QPoint(-10, 0)), QPoint(140, 150));
1753 QCOMPARE(subWindow1->mapToGlobal(QPoint(0, -10)), QPoint(150, 140));
1754 QCOMPARE(subWindow1->mapToGlobal(QPoint(100, 100)), QPoint(250, 250));
1755 QCOMPARE(subWindow1->mapToGlobal(QPoint(110, 100)), QPoint(260, 250));
1756 QCOMPARE(subWindow1->mapToGlobal(QPoint(100, 110)), QPoint(250, 260));
1757 QCOMPARE(subWindow1->mapFromGlobal(QPoint(150, 150)), QPoint(0, 0));
1758 QCOMPARE(subWindow1->mapFromGlobal(QPoint(160, 150)), QPoint(10, 0));
1759 QCOMPARE(subWindow1->mapFromGlobal(QPoint(150, 160)), QPoint(0, 10));
1760 QCOMPARE(subWindow1->mapFromGlobal(QPoint(140, 150)), QPoint(-10, 0));
1761 QCOMPARE(subWindow1->mapFromGlobal(QPoint(150, 140)), QPoint(0, -10));
1762 QCOMPARE(subWindow1->mapFromGlobal(QPoint(250, 250)), QPoint(100, 100));
1763 QCOMPARE(subWindow1->mapFromGlobal(QPoint(260, 250)), QPoint(110, 100));
1764 QCOMPARE(subWindow1->mapFromGlobal(QPoint(250, 260)), QPoint(100, 110));
1765 QCOMPARE(subWindow1->mapToParent(QPoint(0, 0)), QPoint(50, 50));
1766 QCOMPARE(subWindow1->mapToParent(QPoint(10, 0)), QPoint(60, 50));
1767 QCOMPARE(subWindow1->mapToParent(QPoint(0, 10)), QPoint(50, 60));
1768 QCOMPARE(subWindow1->mapToParent(QPoint(-10, 0)), QPoint(40, 50));
1769 QCOMPARE(subWindow1->mapToParent(QPoint(0, -10)), QPoint(50, 40));
1770 QCOMPARE(subWindow1->mapToParent(QPoint(100, 100)), QPoint(150, 150));
1771 QCOMPARE(subWindow1->mapToParent(QPoint(110, 100)), QPoint(160, 150));
1772 QCOMPARE(subWindow1->mapToParent(QPoint(100, 110)), QPoint(150, 160));
1773 QCOMPARE(subWindow1->mapFromParent(QPoint(50, 50)), QPoint(0, 0));
1774 QCOMPARE(subWindow1->mapFromParent(QPoint(60, 50)), QPoint(10, 0));
1775 QCOMPARE(subWindow1->mapFromParent(QPoint(50, 60)), QPoint(0, 10));
1776 QCOMPARE(subWindow1->mapFromParent(QPoint(40, 50)), QPoint(-10, 0));
1777 QCOMPARE(subWindow1->mapFromParent(QPoint(50, 40)), QPoint(0, -10));
1778 QCOMPARE(subWindow1->mapFromParent(QPoint(150, 150)), QPoint(100, 100));
1779 QCOMPARE(subWindow1->mapFromParent(QPoint(160, 150)), QPoint(110, 100));
1780 QCOMPARE(subWindow1->mapFromParent(QPoint(150, 160)), QPoint(100, 110));
1783 QCOMPARE(subSubWindow->mapToGlobal(QPoint(0, 0)), QPoint(160, 160));
1784 QCOMPARE(subSubWindow->mapToGlobal(QPoint(10, 0)), QPoint(170, 160));
1785 QCOMPARE(subSubWindow->mapToGlobal(QPoint(0, 10)), QPoint(160, 170));
1786 QCOMPARE(subSubWindow->mapToGlobal(QPoint(-10, 0)), QPoint(150, 160));
1787 QCOMPARE(subSubWindow->mapToGlobal(QPoint(0, -10)), QPoint(160, 150));
1788 QCOMPARE(subSubWindow->mapToGlobal(QPoint(100, 100)), QPoint(260, 260));
1789 QCOMPARE(subSubWindow->mapToGlobal(QPoint(110, 100)), QPoint(270, 260));
1790 QCOMPARE(subSubWindow->mapToGlobal(QPoint(100, 110)), QPoint(260, 270));
1791 QCOMPARE(subSubWindow->mapFromGlobal(QPoint(160, 160)), QPoint(0, 0));
1792 QCOMPARE(subSubWindow->mapFromGlobal(QPoint(170, 160)), QPoint(10, 0));
1793 QCOMPARE(subSubWindow->mapFromGlobal(QPoint(160, 170)), QPoint(0, 10));
1794 QCOMPARE(subSubWindow->mapFromGlobal(QPoint(150, 160)), QPoint(-10, 0));
1795 QCOMPARE(subSubWindow->mapFromGlobal(QPoint(160, 150)), QPoint(0, -10));
1796 QCOMPARE(subSubWindow->mapFromGlobal(QPoint(260, 260)), QPoint(100, 100));
1797 QCOMPARE(subSubWindow->mapFromGlobal(QPoint(270, 260)), QPoint(110, 100));
1798 QCOMPARE(subSubWindow->mapFromGlobal(QPoint(260, 270)), QPoint(100, 110));
1799 QCOMPARE(subSubWindow->mapToParent(QPoint(0, 0)), QPoint(10, 10));
1800 QCOMPARE(subSubWindow->mapToParent(QPoint(10, 0)), QPoint(20, 10));
1801 QCOMPARE(subSubWindow->mapToParent(QPoint(0, 10)), QPoint(10, 20));
1802 QCOMPARE(subSubWindow->mapToParent(QPoint(-10, 0)), QPoint(0, 10));
1803 QCOMPARE(subSubWindow->mapToParent(QPoint(0, -10)), QPoint(10, 0));
1804 QCOMPARE(subSubWindow->mapToParent(QPoint(100, 100)), QPoint(110, 110));
1805 QCOMPARE(subSubWindow->mapToParent(QPoint(110, 100)), QPoint(120, 110));
1806 QCOMPARE(subSubWindow->mapToParent(QPoint(100, 110)), QPoint(110, 120));
1807 QCOMPARE(subSubWindow->mapFromParent(QPoint(10, 10)), QPoint(0, 0));
1808 QCOMPARE(subSubWindow->mapFromParent(QPoint(20, 10)), QPoint(10, 0));
1809 QCOMPARE(subSubWindow->mapFromParent(QPoint(10, 20)), QPoint(0, 10));
1810 QCOMPARE(subSubWindow->mapFromParent(QPoint(0, 10)), QPoint(-10, 0));
1811 QCOMPARE(subSubWindow->mapFromParent(QPoint(10, 0)), QPoint(0, -10));
1812 QCOMPARE(subSubWindow->mapFromParent(QPoint(110, 110)), QPoint(100, 100));
1813 QCOMPARE(subSubWindow->mapFromParent(QPoint(120, 110)), QPoint(110, 100));
1814 QCOMPARE(subSubWindow->mapFromParent(QPoint(110, 120)), QPoint(100, 110));
1817 void tst_QWidget::focusChainOnReparent()
1827 QWidget *expectedOriginalChain[8] = {&
window, child1, child2, child3, child21, child22, child4, &
window};
1829 for (
auto expectedOriginal : expectedOriginalChain) {
1831 w =
w->nextInFocusChain();
1833 for (
int i = 7;
i >= 0; --
i) {
1834 w =
w->previousInFocusChain();
1839 child2->setParent(&window2);
1841 QWidget *expectedNewChain[5] = {&window2, child2, child21, child22, &window2};
1843 for (
auto expectedNew : expectedNewChain) {
1845 w =
w->nextInFocusChain();
1847 for (
int i = 4;
i >= 0; --
i) {
1848 w =
w->previousInFocusChain();
1854 for (
auto expectedOld : expectedOldChain) {
1856 w =
w->nextInFocusChain();
1858 for (
int i = 4;
i >= 0; --
i) {
1859 w =
w->previousInFocusChain();
1865 void tst_QWidget::focusChainOnHide()
1870 parent->resize(200, 200);
1880 child->activateWindow();
1897 box =
new QVBoxLayout(
this);
1903 focusNextPrevChild(
true);
1908 focusNextPrevChild(
false);
1925 QHBoxLayout* hbox =
new QHBoxLayout(
this);
1937 void tst_QWidget::defaultTabOrder()
1940 QSKIP(
"Wayland: This fails. Figure out why.");
1942 const int compositeCount = 2;
1947 container.
box->addWidget(firstEdit);
1949 for (
int i = 0;
i < compositeCount;
i++) {
1951 container.
box->addWidget(composite[
i]);
1955 container.
box->addWidget(lastEdit);
1959 container.activateWindow();
1966 for (
int i = 0;
i < compositeCount; ++
i) {
1968 QVERIFY(composite[
i]->lineEdit1->hasFocus());
1971 QVERIFY(!composite[
i]->lineEdit1->hasFocus());
1980 for (
int i = compositeCount - 1;
i >= 0; --
i) {
1982 QVERIFY(!composite[
i]->lineEdit1->hasFocus());
1986 QVERIFY(composite[
i]->lineEdit1->hasFocus());
1994 void tst_QWidget::reverseTabOrder()
1997 QSKIP(
"Wayland: This fails. Figure out why.");
1999 const int compositeCount = 2;
2005 container.
box->addWidget(firstEdit);
2007 for (
int i = 0;
i < compositeCount;
i++) {
2009 container.
box->addWidget(composite[
i]);
2013 container.
box->addWidget(lastEdit);
2016 for (
int i = 0;
i < compositeCount; ++
i)
2020 container.activateWindow();
2028 for (
int i = 0;
i < compositeCount; ++
i) {
2030 QVERIFY(!composite[
i]->lineEdit1->hasFocus());
2033 QVERIFY(composite[
i]->lineEdit1->hasFocus());
2043 for (
int i = compositeCount - 1;
i >= 0; --
i) {
2045 QVERIFY(composite[
i]->lineEdit1->hasFocus());
2048 QVERIFY(!composite[
i]->lineEdit1->hasFocus());
2056 void tst_QWidget::tabOrderWithProxy()
2059 QSKIP(
"Wayland: This fails. Figure out why.");
2061 const int compositeCount = 2;
2067 container.
box->addWidget(firstEdit);
2069 for (
int i = 0;
i < compositeCount;
i++) {
2071 container.
box->addWidget(composite[
i]);
2079 container.
box->addWidget(lastEdit);
2082 container.activateWindow();
2090 for (
int i = 0;
i < compositeCount; ++
i) {
2092 QVERIFY(!composite[
i]->lineEdit1->hasFocus());
2104 for (
int i = compositeCount - 1;
i >= 0; --
i) {
2106 QVERIFY(!composite[
i]->lineEdit1->hasFocus());
2109 QVERIFY(composite[
i]->lineEdit1->hasFocus());
2117 void tst_QWidget::tabOrderWithProxyDisabled()
2127 auto *containingLayout =
new QVBoxLayout;
2132 containingLayout->addWidget(&lineEdit2);
2133 containingLayout->addWidget(&lineEdit3);
2134 containingWidget.setLayout(containingLayout);
2135 containingWidget.setFocusProxy(&lineEdit2);
2138 container.
box->addWidget(&lineEdit1);
2139 container.
box->addWidget(&containingWidget);
2142 container.activateWindow();
2146 QSKIP(
"Window failed to activate, skipping test");
2168 void tst_QWidget::tabOrderWithCompoundWidgets()
2171 QSKIP(
"Wayland: This fails. Figure out why.");
2173 const int compositeCount = 4;
2179 container.
box->addWidget(firstEdit);
2181 for (
int i = 0;
i < compositeCount;
i++) {
2183 container.
box->addWidget(composite[
i]);
2195 container.
box->addWidget(lastEdit);
2202 for (
int i = compositeCount - 1;
i >= 1; --
i)
2207 container.activateWindow();
2219 for (
int i = compositeCount - 1;
i >= 0; --
i) {
2222 QVERIFY(!
c->lineEdit1->hasFocus());
2224 QVERIFY(!
c->lineEdit3->hasFocus());
2226 QVERIFY(!
c->lineEdit1->hasFocus());
2227 QVERIFY(!
c->lineEdit2->hasFocus());
2239 for (
int i = 0;
i < compositeCount; ++
i) {
2242 QVERIFY(!
c->lineEdit1->hasFocus());
2243 QVERIFY(!
c->lineEdit2->hasFocus());
2246 QVERIFY(!
c->lineEdit1->hasFocus());
2248 QVERIFY(!
c->lineEdit3->hasFocus());
2251 QVERIFY(!
c->lineEdit2->hasFocus());
2252 QVERIFY(!
c->lineEdit3->hasFocus());
2262 QWidget *cur =
start;
2266 cur = bForward ? widgetPrivate->
focus_next : widgetPrivate->focus_prev;
2267 }
while (cur !=
start);
2272 static void dumpFocusChain(QWidget *
start,
bool bForward,
const char *
desc =
nullptr)
2274 #ifdef DEBUG_FOCUS_CHAIN
2275 qDebug() <<
"Dump focus chain, start:" <<
start <<
"isForward:" << bForward <<
desc;
2276 QWidget *cur =
start;
2280 cur = bForward ? widgetPrivate->
focus_next : widgetPrivate->focus_prev;
2281 }
while (cur !=
start);
2289 void tst_QWidget::tabOrderWithCompoundWidgetsNoFocusPolicy()
2294 spinbox1.setObjectName(
"spinbox1");
2296 spinbox2.setObjectName(
"spinbox2");
2298 spinbox3.setObjectName(
"spinbox3");
2303 container.
box->addWidget(&spinbox1);
2304 container.
box->addWidget(&spinbox2);
2305 container.
box->addWidget(&spinbox3);
2308 container.activateWindow();
2312 QSKIP(
"Window failed to activate, skipping test");
2334 void tst_QWidget::tabOrderNoChange()
2337 auto *verticalLayout =
new QVBoxLayout(&
w);
2341 verticalLayout->addWidget(tabWidget);
2343 const auto focusChainForward = getFocusChain(&
w,
true);
2344 const auto focusChainBackward = getFocusChain(&
w,
false);
2345 dumpFocusChain(&
w,
true);
2347 dumpFocusChain(&
w,
true);
2348 QCOMPARE(focusChainForward, getFocusChain(&
w,
true));
2349 QCOMPARE(focusChainBackward, getFocusChain(&
w,
false));
2352 void tst_QWidget::tabOrderNoChange2()
2355 auto *verticalLayout =
new QVBoxLayout(&
w);
2357 tabWidget->setObjectName(
"tabWidget");
2358 verticalLayout->addWidget(tabWidget);
2360 auto *tab1 =
new QWidget(tabWidget);
2361 tab1->setObjectName(
"tab1");
2362 auto *vLay1 =
new QVBoxLayout(tab1);
2364 le1->setObjectName(
"le1");
2366 le2->setObjectName(
"le2");
2367 vLay1->addWidget(le1);
2368 vLay1->addWidget(le2);
2371 auto *tab2 =
new QWidget(tabWidget);
2372 tab2->setObjectName(
"tab2");
2373 auto *vLay2 =
new QVBoxLayout(tab2);
2375 le3->setObjectName(
"le3");
2377 le4->setObjectName(
"le4");
2378 vLay2->addWidget(le3);
2379 vLay2->addWidget(le4);
2382 const auto focusChainForward = getFocusChain(&
w,
true);
2383 const auto focusChainBackward = getFocusChain(&
w,
false);
2384 dumpFocusChain(&
w,
true);
2385 dumpFocusChain(&
w,
false);
2391 dumpFocusChain(&
w,
true,
"QWidget::setTabOrder(le1, le2)");
2393 dumpFocusChain(&
w,
true,
"QWidget::setTabOrder(le2, le3)");
2395 dumpFocusChain(&
w,
true,
"QWidget::setTabOrder(le3, le4)");
2397 dumpFocusChain(&
w,
true,
"QWidget::setTabOrder(le4, tabWidget)");
2398 dumpFocusChain(&
w,
false);
2400 QCOMPARE(focusChainForward, getFocusChain(&
w,
true));
2401 QCOMPARE(focusChainBackward, getFocusChain(&
w,
false));
2404 void tst_QWidget::appFocusWidgetWithFocusProxyLater()
2407 QSKIP(
"Wayland: This fails. Figure out why.");
2431 void tst_QWidget::appFocusWidgetWhenLosingFocusProxy()
2434 QSKIP(
"Wayland: This fails. Figure out why.");
2459 void tst_QWidget::explicitTabOrderWithComplexWidget()
2465 window.box->addWidget(lineEditOne);
2467 window.box->addWidget(lineEditTwo);
2469 lineEditOne->setFocus();
2485 void tst_QWidget::explicitTabOrderWithSpinBox_QTBUG81097()
2493 window.box->addWidget(spinBoxOne);
2494 window.box->addWidget(spinBoxTwo);
2498 spinBoxOne->setFocus();
2516 #if defined(Q_OS_WIN)
2517 void tst_QWidget::activation()
2522 widget1.setObjectName(
"activation-Widget1");
2523 widget1.setWindowTitle(widget1.objectName());
2526 widget1.setObjectName(
"activation-Widget2");
2527 widget1.setWindowTitle(widget2.objectName());
2533 widget2.showMinimized();
2536 widget2.showMaximized();
2538 widget2.showMinimized();
2540 widget2.showNormal();
2552 widget->
window()->windowHandle()->installEventFilter(
this);
2565 void tst_QWidget::windowState()
2568 QSKIP(
"QTBUG-52974");
2572 QSKIP(
"X11: Many window managers do not support window state properly, which causes this test to fail.");
2574 QSKIP(
"Wayland: This fails. Figure out why.");
2577 QSize
size = m_testWidgetSize;
2585 pos = QPoint(10, 10);
2589 widget1.resize(
size);
2594 widget1.setWindowTitle(widget1.objectName());
2598 #define VERIFY_STATE(s) \
2599 QCOMPARE(int(widget1.windowState() & stateMask), int(s)); \
2600 QCOMPARE(int(widget1.windowHandle()->windowStates() & stateMask), int(s))
2609 widget1.setVisible(
true);
2692 QVERIFY(!(widget1.windowState() & stateMask));
2700 void tst_QWidget::showMaximized()
2704 layout =
new QHBoxLayout;
2714 layouted.setLayout(
layout);
2716 plain.showMaximized();
2722 layouted.showMaximized();
2725 layouted.showNormal();
2729 if (layouted.size() != layouted.sizeHint())
2731 QCOMPARE(layouted.size(), layouted.sizeHint());
2733 layouted.showMaximized();
2734 QVERIFY(layouted.isMaximized());
2735 QVERIFY(layouted.isVisible());
2738 QVERIFY(layouted.isMaximized());
2739 QVERIFY(!layouted.isVisible());
2741 layouted.showMaximized();
2742 QVERIFY(layouted.isMaximized());
2743 QVERIFY(layouted.isVisible());
2745 layouted.showMinimized();
2746 QVERIFY(layouted.isMinimized());
2747 QVERIFY(layouted.isMaximized());
2749 layouted.showMaximized();
2750 QVERIFY(!layouted.isMinimized());
2751 QVERIFY(layouted.isMaximized());
2752 QVERIFY(layouted.isVisible());
2754 layouted.showMinimized();
2755 QVERIFY(layouted.isMinimized());
2756 QVERIFY(layouted.isMaximized());
2758 layouted.showMaximized();
2759 QVERIFY(!layouted.isMinimized());
2760 QVERIFY(layouted.isMaximized());
2761 QVERIFY(layouted.isVisible());
2772 setFrameless(&widget);
2779 void tst_QWidget::showFullScreen()
2782 QSKIP(
"QTBUG-52974");
2791 layout =
new QHBoxLayout;
2797 layouted.setLayout(
layout);
2799 plain.showFullScreen();
2801 QVERIFY(plain.windowHandle());
2802 QVERIFY(plain.windowHandle()->screen());
2803 const QRect expectedFullScreenGeometry = plain.windowHandle()->screen()->geometry();
2804 QTRY_COMPARE(plain.geometry(), expectedFullScreenGeometry);
2809 layouted.showFullScreen();
2811 QTRY_COMPARE(layouted.geometry(), expectedFullScreenGeometry);
2813 layouted.showNormal();
2817 if (layouted.size() != layouted.sizeHint())
2819 QCOMPARE(layouted.size(), layouted.sizeHint());
2821 layouted.showFullScreen();
2822 QVERIFY(layouted.isFullScreen());
2823 QVERIFY(layouted.isVisible());
2824 QTRY_COMPARE(layouted.geometry(), expectedFullScreenGeometry);
2827 QVERIFY(layouted.isFullScreen());
2828 QVERIFY(!layouted.isVisible());
2830 layouted.showFullScreen();
2831 QVERIFY(layouted.isFullScreen());
2832 QVERIFY(layouted.isVisible());
2833 QTRY_COMPARE(layouted.geometry(), expectedFullScreenGeometry);
2835 layouted.showMinimized();
2836 QVERIFY(layouted.isMinimized());
2837 QVERIFY(layouted.isFullScreen());
2839 layouted.showFullScreen();
2840 QVERIFY(!layouted.isMinimized());
2841 QVERIFY(layouted.isFullScreen());
2842 QVERIFY(layouted.isVisible());
2843 QTRY_COMPARE(layouted.geometry(), expectedFullScreenGeometry);
2845 layouted.showMinimized();
2846 QVERIFY(layouted.isMinimized());
2847 QVERIFY(layouted.isFullScreen());
2849 layouted.showFullScreen();
2850 QVERIFY(!layouted.isMinimized());
2851 QVERIFY(layouted.isFullScreen());
2852 QVERIFY(layouted.isVisible());
2853 QTRY_COMPARE(layouted.geometry(), expectedFullScreenGeometry);
2860 QTRY_COMPARE(layouted.geometry(), expectedFullScreenGeometry);
2869 setWindowTitle(objectName());
2882 void tst_QWidget::resizeEvent()
2887 wParent.resize(m_testWidgetSize);
2889 QTestPrivate::androidCompatibleShow(&wParent);
2893 QSize safeSize(640,480);
2894 if (wChild.size() == safeSize)
2895 safeSize.setWidth(639);
2896 wChild.resize(safeSize);
2898 QTestPrivate::androidCompatibleShow(&wParent);
2905 wTopLevel.resize(m_testWidgetSize);
2906 QTestPrivate::androidCompatibleShow(&wTopLevel);
2910 QSize safeSize(640,480);
2911 if (wTopLevel.size() == safeSize)
2912 safeSize.setWidth(639);
2913 wTopLevel.resize(safeSize);
2915 QTestPrivate::androidCompatibleShow(&wTopLevel);
2921 void tst_QWidget::showMinimized()
2924 QSKIP(
"Wayland: Neither xdg_shell, wl_shell or ivi_application support "
2925 "letting a client know whether it's minimized. So on these shells "
2926 "Qt Wayland will always report that it's unmimized.");
2931 plain.move(100, 100);
2932 plain.resize(200, 200);
2933 QPoint
pos = plain.pos();
2935 plain.showMinimized();
2942 QVERIFY(!plain.isMinimized());
2947 plain.showMinimized();
2957 plain.showMinimized();
2961 plain.setGeometry(200, 200, 300, 300);
2963 QCOMPARE(plain.geometry(), QRect(200, 200, 300, 300));
2973 void tst_QWidget::showMinimizedKeepsFocus()
2976 QSKIP(
"QTBUG-26424");
2978 QSKIP(
"Window activation is not supported.");
2980 QSKIP(
"Platform offscreen does not support showMinimized()");
3040 child->setParent(
nullptr);
3060 child->setEnabled(
false);
3081 child->clearFocus();
3095 if (!macHasAccessToWindowsServer())
3100 if (!macHasAccessToWindowsServer())
3108 void tst_QWidget::reparent()
3112 const QPoint parentPosition = m_availableTopLeft + QPoint(300, 300);
3113 parent.setGeometry(QRect(parentPosition, m_testWidgetSize));
3116 child.setObjectName(
"child");
3120 child.setPalette(pal1);
3123 childTLW.setObjectName(
QStringLiteral(
"childTLW ") + __FUNCTION__);
3124 childTLW.setWindowTitle(childTLW.objectName());
3125 childTLW.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize));
3127 pal2.setColor(childTLW.backgroundRole(),
Qt::yellow);
3128 childTLW.setPalette(pal2);
3130 QTestPrivate::androidCompatibleShow(&
parent);
3131 QTestPrivate::androidCompatibleShow(&childTLW);
3134 parent.move(parentPosition);
3136 QPoint childPos =
parent.mapToGlobal(
child.pos());
3137 QPoint tlwPos = childTLW.pos();
3141 QTestPrivate::androidCompatibleShow(&
child);
3145 QEXPECT_FAIL(
"",
"On X11, the window manager will apply NorthWestGravity rules to 'child', which"
3146 " means the top-left corner of the window frame will be placed at 'childPos'"
3147 " causing this test to fail.",
Continue);
3154 void tst_QWidget::setScreen()
3157 if (screens.count() < 2)
3158 QSKIP(
"This test tests nothing on a machine with a single screen.");
3160 QScreen *screen0 = screens.at(0);
3161 QScreen *screen1 = screens.at(1);
3165 window.setScreen(screen0);
3167 window.setScreen(screen1);
3173 child.setScreen(childScreen == screen0 ? screen1 : screen0);
3178 void tst_QWidget::icon()
3181 QSKIP(
"QTBUG-52974");
3187 testWidget->resize(m_testWidgetSize);
3188 testWidget->setWindowTitle(__FUNCTION__);
3189 centerOnScreen(testWidget.data());
3192 testWidget->setWindowIcon(
p);
3194 QVERIFY(!testWidget->windowIcon().isNull());
3196 QVERIFY(!testWidget->windowIcon().isNull());
3197 testWidget->showFullScreen();
3198 QVERIFY(!testWidget->windowIcon().isNull());
3199 testWidget->showNormal();
3200 QVERIFY(!testWidget->windowIcon().isNull());
3203 void tst_QWidget::hideWhenFocusWidgetIsChild()
3206 QSKIP(
"Window activation is not supported.");
3209 testWidget->setWindowTitle(__FUNCTION__);
3210 testWidget->resize(m_testWidgetSize);
3211 centerOnScreen(testWidget.data());
3213 parentWidget->setObjectName(
"parentWidget");
3214 parentWidget->setGeometry(0, 0, 100, 100);
3222 edit2->
move(110, 100);
3225 testWidget->activateWindow();
3228 QString actualFocusWidget, expectedFocusWidget;
3230 QSKIP(
"X11: Your window manager is too broken for this test");
3235 QCOMPARE(actualFocusWidget, expectedFocusWidget);
3237 parentWidget->hide();
3241 QCOMPARE(actualFocusWidget, expectedFocusWidget);
3244 void tst_QWidget::normalGeometry()
3247 QSKIP(
"Wayland: This fails. Figure out why.");
3250 parent.setWindowTitle(
"NormalGeometry parent");
3256 parent.setGeometry(QRect(m_availableTopLeft + QPoint(100 ,100), m_testWidgetSize));
3261 const QRect normalGeometry =
parent.geometry();
3315 QSKIP(
"QTBUG-26424");
3344 stateChangeWatcher.lastWindowStates = {};
3353 void tst_QWidget::setGeometry()
3359 const QSize initialSize = 2 * m_testWidgetSize;
3360 QRect
tr(m_availableTopLeft + QPoint(100,100), initialSize);
3361 QRect cr(50,50,50,50);
3362 tlw.setGeometry(
tr);
3369 tr = QRect(m_availableTopLeft, initialSize / 2);
3370 tlw.setGeometry(
tr);
3373 if (!QTest::qWaitFor([&tlw]{
return tlw.frameGeometry() == tlw.geometry(); }))
3374 QSKIP(
"Your window manager is too broken for this test");
3380 void tst_QWidget::setGeometryHidden()
3383 QSKIP(
"Platform does not support QWidget::setGeometry() - skipping");
3389 const QRect
tr(m_availableTopLeft + QPoint(100, 100), 2 * m_testWidgetSize);
3390 const QRect cr(QPoint(50, 50), m_testWidgetSize);
3391 tlw.setGeometry(
tr);
3397 tlw.setGeometry(cr);
3404 tlw.setGeometry(cr);
3407 tlw.resize(cr.size());
3412 void tst_QWidget::windowOpacity()
3424 child.setWindowOpacity(0.0);
3429 child.setWindowOpacity(1.0);
3434 child.setWindowOpacity(2.0);
3439 child.setWindowOpacity(-1.0);
3464 switch (
event->type()) {
3500 void tst_QWidget::lostUpdatesOnHide()
3516 void tst_QWidget::raise()
3518 std::unique_ptr<QWidget> parentPtr(
new QWidget);
3519 parentPtr->resize(200, 200);
3521 parentPtr->setWindowTitle(parentPtr->objectName());
3526 allChildren.
append(child1);
3530 allChildren.
append(child2);
3534 allChildren.
append(child3);
3538 allChildren.
append(child4);
3545 QSKIP(
"Cocoa has no Z-Order for views, we hack it, but it results in paint events.");
3549 QObjectList list1{child1, child2, child3, child4};
3550 QCOMPARE(parentPtr->children(), list1);
3554 int expectedPaintEvents =
child == child4 ? 1 : 0;
3555 if (expectedPaintEvents == 0) {
3565 for (
int i = 0;
i < 5; ++
i)
3570 int expectedPaintEvents =
child == child2 ? 1 : 0;
3571 int expectedZOrderChangeEvents =
child == child2 ? 1 : 0;
3573 QCOMPARE(
child->numZOrderChangeEvents, expectedZOrderChangeEvents);
3578 list2 << child1 << child3 << child4 << child2;
3586 parent->setParent(&topLevel);
3591 onTop->
resize(topLevel.size());
3602 for (
int i = 0;
i < 5; ++
i)
3613 int expectedPaintEvents = 0;
3614 int expectedZOrderChangeEvents =
child == child3 ? 1 : 0;
3616 QCOMPARE(
child->numZOrderChangeEvents, expectedZOrderChangeEvents);
3621 void tst_QWidget::lower()
3626 parent->resize(200, 200);
3631 allChildren.
append(child1);
3635 allChildren.
append(child2);
3639 allChildren.
append(child3);
3643 allChildren.
append(child4);
3648 QObjectList list1{child1, child2, child3, child4};
3653 int expectedPaintEvents =
child == child4 ? 1 : 0;
3654 if (expectedPaintEvents == 0) {
3664 for (
int i = 0;
i < 5; ++
i)
3670 int expectedPaintEvents =
child == child3 ? 1 : 0;
3671 int expectedZOrderChangeEvents =
child == child4 ? 1 : 0;
3678 list2 << child4 << child1 << child2 << child3;
3682 void tst_QWidget::stackUnder()
3685 QSKIP(
"QTBUG-52974: Cocoa has no Z-Order for views, we hack it, but it results in paint events.");
3691 parent->resize(200, 200);
3696 allChildren.
append(child1);
3700 allChildren.
append(child2);
3704 allChildren.
append(child3);
3708 allChildren.
append(child4);
3712 QObjectList list1{child1, child2, child3, child4};
3716 int expectedPaintEvents =
child == child4 ? 1 : 0;
3717 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
3718 if (expectedPaintEvents == 1 &&
child->numPaintEvents == 2)
3726 for (
int i = 0;
i < 5; ++
i)
3734 int expectedPaintEvents =
child == child3 ? 1 : 0;
3735 int expectedZOrderChangeEvents =
child == child4 ? 1 : 0;
3741 for (
int i = 0;
i < 5; ++
i)
3749 int expectedZOrderChangeEvents =
child == child1 ? 1 : 0;
3750 if (
child == child3) {
3769 a << QPoint(0, 0) << QPoint(
w/2,
h/2) << QPoint(
w, 0)
3770 << QPoint(
w/2,
h) << QPoint(0, 0);
3784 setWindowTitle(objectName());
3785 QWidget *
child =
this;
3786 for (
int i = 0;
i < 32; ++
i) {
3794 for (QObject *
child : children())
3809 static QPixmap grabFromWidget(QWidget *
w,
const QRect &
rect)
3812 const qreal devicePixelRatio =
pixmap.devicePixelRatio();
3816 pixmap.setDevicePixelRatio(1);
3821 void tst_QWidget::testContentsPropagation()
3824 QSKIP(
"This test does not work with scaling.");
3827 widget.setContentsPropagation(
false);
3828 QPixmap widgetSnapshot =
widget.
grab(QRect(QPoint(0, 0), QSize(-1, -1)));
3830 QPixmap correct(500, 500);
3835 QVERIFY(widgetSnapshot.toImage() != correct.toImage());
3837 widget.setContentsPropagation(
true);
3838 widgetSnapshot = widgetSnapshot =
widget.
grab(QRect(QPoint(0, 0), QSize(-1, -1)));
3849 void tst_QWidget::saveRestoreGeometry()
3852 QSKIP(
"QTBUG-52974");
3856 QSKIP(
"Wayland: This fails. Figure out why.");
3857 const QPoint
position = m_availableTopLeft + QPoint(100, 100);
3858 const QSize
size = m_testWidgetSize;
3885 const QByteArray garbage(
"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc");
3987 void tst_QWidget::restoreVersion1Geometry_data()
3990 QSKIP(
"Wayland: This fails. Figure out why.");
3991 QTest::addColumn<QString>(
"fileName");
3992 QTest::addColumn<Qt::WindowState>(
"expectedWindowState");
3993 QTest::addColumn<QPoint>(
"expectedPosition");
3994 QTest::addColumn<QSize>(
"expectedSize");
3995 QTest::addColumn<QRect>(
"expectedNormalGeometry");
3997 const QSize
size(200, 200);
3998 const QRect normalGeometry(102, 124, 200, 200);
4009 void tst_QWidget::restoreVersion1Geometry()
4013 QFETCH(QPoint, expectedPosition);
4015 QFETCH(QSize, expectedSize);
4016 QFETCH(QRect, expectedNormalGeometry);
4019 QSKIP(
"Skipping due to minimum decorated window size on Windows");
4063 widgetToSave.move(expectedPosition);
4064 widgetToSave.resize(expectedSize);
4065 widgetToSave.show();
4068 widgetToSave.setWindowState(Qt::WindowStates(expectedWindowState));
4071 QByteArray geometryToSave = widgetToSave.saveGeometry();
4076 f.write(geometryToSave);
4082 void tst_QWidget::widgetAt()
4085 QSKIP(
"QTBUG-52974");
4089 QSKIP(
"Wayland: This fails. Figure out why.");
4091 QSKIP(
"Platform offscreen does not support lower()/raise() or WindowMasks");
4095 const QPoint referencePos = m_availableTopLeft + QPoint(100, 100);
4097 w1->setGeometry(QRect(referencePos, QSize(m_testWidgetSize.width(), 150)));
4099 w1->setWindowTitle(
w1->objectName());
4101 w2->setGeometry(QRect(referencePos + QPoint(50, 50), QSize(m_testWidgetSize.width(), 100)));
4103 w2->setWindowTitle(
w2->objectName());
4106 const QPoint testPos = referencePos + QPoint(100, 100);
4123 w3->setGeometry(10,10,50,50);
4124 w3->setObjectName(
"w3");
4133 QSKIP(
"Platform does not support WindowMasks");
4136 QRegion rgn = QRect(QPoint(0,0),
w2->size());
4137 QPoint point =
w2->mapFromGlobal(testPos);
4138 rgn -= QRect(point, QSize(1,1));
4150 p.drawPoint(
w2->mapFromGlobal(testPos));
4157 void tst_QWidget::task110173()
4164 pb1->move(100, 100);
4168 pb2->move(300, 300);
4194 void tst_QWidget::testDeletionInEventHandlers()
4198 w->deleteThis =
true;
4215 w->deleteThis =
true;
4223 w->deleteThis =
true;
4231 w->deleteThis =
true;
4239 w->deleteThis =
true;
4241 qApp->notify(
w, &me);
4248 w->deleteThis =
true;
4262 w->deleteThis =
true;
4270 w->deleteThis =
true;
4271 w->setMouseTracking(
true);
4276 w->setMouseTracking(
true);
4278 w->deleteThis =
true;
4286 class MaskedPainter :
public QWidget
4292 :
mask(20, 20, 50, 50)
4307 bool verifyWidgetMask(QWidget *
widget, QRect
mask)
4315 return (masked ==
red);
4318 void tst_QWidget::setMask()
4333 QRect
mask =
w.mask;
4362 for (QRect
r :
e->region()) {
4374 void tst_QWidget::optimizedResizeMove()
4377 QSKIP(
"Wayland: This fails. Figure out why.");
4383 staticWidget.gotPaintEvent =
false;
4384 staticWidget.move(150, 150);
4385 staticWidget.resize(150, 150);
4390 staticWidget.gotPaintEvent =
false;
4391 staticWidget.move(staticWidget.pos() + QPoint(10, 10));
4393 QCOMPARE(staticWidget.gotPaintEvent,
false);
4395 staticWidget.gotPaintEvent =
false;
4396 staticWidget.move(staticWidget.pos() + QPoint(-10, -10));
4398 QCOMPARE(staticWidget.gotPaintEvent,
false);
4400 staticWidget.gotPaintEvent =
false;
4401 staticWidget.move(staticWidget.pos() + QPoint(-10, 10));
4403 QCOMPARE(staticWidget.gotPaintEvent,
false);
4405 staticWidget.gotPaintEvent =
false;
4406 staticWidget.resize(staticWidget.size() + QSize(10, 10));
4408 QCOMPARE(staticWidget.partial,
true);
4410 staticWidget.gotPaintEvent =
false;
4411 staticWidget.resize(staticWidget.size() + QSize(-10, -10));
4413 QCOMPARE(staticWidget.gotPaintEvent,
false);
4415 staticWidget.gotPaintEvent =
false;
4416 staticWidget.resize(staticWidget.size() + QSize(10, -10));
4418 QCOMPARE(staticWidget.partial,
true);
4420 staticWidget.gotPaintEvent =
false;
4421 staticWidget.move(staticWidget.pos() + QPoint(10, 10));
4422 staticWidget.resize(staticWidget.size() + QSize(-10, -10));
4424 QCOMPARE(staticWidget.gotPaintEvent,
false);
4426 staticWidget.gotPaintEvent =
false;
4427 staticWidget.move(staticWidget.pos() + QPoint(10, 10));
4428 staticWidget.resize(staticWidget.size() + QSize(10, 10));
4430 QCOMPARE(staticWidget.partial,
true);
4432 staticWidget.gotPaintEvent =
false;
4433 staticWidget.move(staticWidget.pos() + QPoint(-10, -10));
4434 staticWidget.resize(staticWidget.size() + QSize(-10, -10));
4436 QCOMPARE(staticWidget.gotPaintEvent,
false);
4439 staticWidget.gotPaintEvent =
false;
4440 staticWidget.move(staticWidget.pos() + QPoint(-10, -10));
4441 staticWidget.resize(staticWidget.size() + QSize(-10, -10));
4443 QCOMPARE(staticWidget.partial,
false);
4447 staticWidget.gotPaintEvent =
false;
4448 staticWidget.move(staticWidget.pos() + QPoint(10, 10));
4450 QCOMPARE(staticWidget.gotPaintEvent,
false);
4454 void tst_QWidget::optimizedResize_topLevel()
4457 QSKIP(
"Wayland: This fails. Figure out why.");
4460 QSKIP(
"Skip due to rounding errors in the regions.");
4472 #if !defined(Q_OS_WIN32)
4473 topLevel.
resize(topLevel.
size() + QSize(10, 10));
4482 GetWindowRect(winHandleOf(&topLevel), &
rect);
4483 MoveWindow(winHandleOf(&topLevel),
rect.left,
rect.top,
4491 expectedUpdateRegion -= QRect(QPoint(), topLevel.
size() - QSize(10, 10));
4495 QSKIP(
"QTBUG-26424");
4504 : QWidget(
parent), sibling(sibling) {}
4512 void tst_QWidget::childDeletesItsSibling()
4514 auto commonParent =
new QWidget(
nullptr);
4517 child->setParent(commonParent);
4518 delete commonParent;
4524 void tst_QWidget::setMinimumSize()
4527 QSize defaultSize =
w.size();
4529 w.setMinimumSize(defaultSize + QSize(100, 100));
4530 QCOMPARE(
w.size(), defaultSize + QSize(100, 100));
4533 w.setMinimumSize(defaultSize + QSize(50, 50));
4534 QCOMPARE(
w.size(), defaultSize + QSize(100, 100));
4537 w.setMinimumSize(defaultSize + QSize(200, 200));
4538 QCOMPARE(
w.size(), defaultSize + QSize(200, 200));
4541 QSize nonDefaultSize = defaultSize + QSize(5,5);
4542 w.setMinimumSize(nonDefaultSize);
4545 QVERIFY2(
w.height() >= nonDefaultSize.height(),
4546 msgComparisonFailed(
w.height(),
">=", nonDefaultSize.height()));
4547 QVERIFY2(
w.width() >= nonDefaultSize.width(),
4548 msgComparisonFailed(
w.width(),
">=", nonDefaultSize.width()));
4551 void tst_QWidget::setMaximumSize()
4554 QSize defaultSize =
w.size();
4556 w.setMinimumSize(defaultSize + QSize(100, 100));
4557 QCOMPARE(
w.size(), defaultSize + QSize(100, 100));
4559 w.setMinimumSize(defaultSize);
4561 w.setMaximumSize(defaultSize + QSize(200, 200));
4562 QCOMPARE(
w.size(), defaultSize + QSize(100, 100));
4565 w.setMaximumSize(defaultSize + QSize(50, 50));
4566 QCOMPARE(
w.size(), defaultSize + QSize(50, 50));
4570 void tst_QWidget::setFixedSize()
4573 QSKIP(
"Wayland: This fails. Figure out why.");
4576 QSize defaultSize =
w.size();
4578 w.setFixedSize(defaultSize + QSize(100, 100));
4579 QCOMPARE(
w.size(), defaultSize + QSize(100, 100));
4582 w.setFixedSize(defaultSize + QSize(200, 200));
4584 QCOMPARE(
w.minimumSize(), defaultSize + QSize(200,200));
4585 QCOMPARE(
w.maximumSize(), defaultSize + QSize(200,200));
4586 QCOMPARE(
w.size(), defaultSize + QSize(200, 200));
4589 w.setFixedSize(defaultSize + QSize(50, 50));
4590 QCOMPARE(
w.size(), defaultSize + QSize(50, 50));
4594 w.setFixedSize(defaultSize + QSize(50, 50));
4597 w.setFixedSize(defaultSize + QSize(150, 150));
4601 QSKIP(
"QTBUG-26424");
4602 QCOMPARE(
w.size(), defaultSize + QSize(150,150));
4605 void tst_QWidget::ensureCreated()
4676 void tst_QWidget::createAndDestroy()
4721 void tst_QWidget::winIdChangeEvent()
4728 QVERIFY(winIdBefore != winIdAfter);
4736 const WId winIdBefore =
child.winId();
4738 child.setParent(&parent2);
4739 const WId winIdAfter =
child.internalWinId();
4748 QWidget grandparent1, grandparent2;
4751 const WId winIdBefore =
child.winId();
4753 parent.setParent(&grandparent2);
4754 const WId winIdAfter =
child.internalWinId();
4763 const WId winIdBefore =
child.internalWinId();
4764 child.setParent(&parent2);
4765 const WId winIdAfter =
child.internalWinId();
4775 const WId winIdBefore =
child.internalWinId();
4777 const Qt::WindowFlags
flags =
child.windowFlags();
4779 const WId winIdAfter =
child.internalWinId();
4787 void tst_QWidget::persistentWinId()
4797 WId winId1 =
w1->winId();
4798 WId winId2 =
w2->winId();
4799 WId winId3 = w3->winId();
4802 w1->setParent(
nullptr);
4812 w2->setParent(
nullptr);
4824 w3->setParent(
nullptr);
4834 void tst_QWidget::transientParent()
4837 topLevel.
setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize));
4838 topLevel.setWindowTitle(__FUNCTION__);
4842 toolButton->setMenu(
menu);
4843 toolButton->
winId();
4849 void tst_QWidget::showNativeChild()
4852 topLevel.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize));
4853 topLevel.setWindowTitle(__FUNCTION__);
4860 void tst_QWidget::closeAndShowNativeChild()
4864 nativeChild->winId();
4865 nativeChild->setFixedSize(200, 200);
4867 QHBoxLayout *
layout =
new QHBoxLayout;
4868 layout->addWidget(nativeChild);
4869 topLevel.setLayout(
layout);
4872 QVERIFY(!nativeChild->isHidden());
4873 nativeChild->close();
4874 QVERIFY(nativeChild->isHidden());
4875 nativeChild->show();
4876 QVERIFY(!nativeChild->isHidden());
4879 void tst_QWidget::closeAndShowWithNativeChild()
4889 nativeChild->setFixedSize(200, 200);
4891 nativeHiddenChild->setFixedSize(200, 200);
4893 normalChild->setFixedSize(200, 200);
4895 QHBoxLayout *
layout =
new QHBoxLayout;
4896 layout->addWidget(nativeChild);
4897 layout->addWidget(nativeHiddenChild);
4898 layout->addWidget(normalChild);
4899 topLevel.setLayout(
layout);
4901 nativeHiddenChild->hide();
4905 nativeChild->winId();
4906 const QSize originalSize = topLevel.size();
4910 QCOMPARE(nativeChild->isHidden(), normalChild->isHidden());
4911 QCOMPARE(nativeChild->isVisible(), normalChild->isVisible());
4921 QCOMPARE(topLevel.size(), originalSize);
4936 if (
e->spontaneous())
4943 if (
e->spontaneous())
4948 void tst_QWidget::showHideEvent_data()
4950 QTest::addColumn<bool>(
"show");
4951 QTest::addColumn<bool>(
"hide");
4952 QTest::addColumn<bool>(
"create");
4953 QTest::addColumn<int>(
"expectedShowEvents");
4954 QTest::addColumn<int>(
"expectedHideEvents");
4994 void tst_QWidget::showHideEvent()
4999 QFETCH(
int, expectedShowEvents);
5000 QFETCH(
int, expectedHideEvents);
5015 void tst_QWidget::showHideEventWhileMinimize()
5021 QSKIP(
"This test requires window management capabilities");
5027 centerOnScreen(&widget);
5030 const int showEventsBeforeMinimize =
widget.numberOfShowEvents;
5031 const int hideEventsBeforeMinimize =
widget.numberOfHideEvents;
5038 void tst_QWidget::showHideChildrenWhileMinimize_QTBUG50589()
5044 QSKIP(
"This test requires window management capabilities");
5051 parent.resize(m_testWidgetSize);
5056 const int showEventsBeforeMinimize =
child.numberOfSpontaneousShowEvents;
5057 const int hideEventsBeforeMinimize =
child.numberOfSpontaneousHideEvents;
5059 QTRY_COMPARE(
child.numberOfSpontaneousHideEvents, hideEventsBeforeMinimize + 1);
5061 QTRY_COMPARE(
child.numberOfSpontaneousShowEvents, showEventsBeforeMinimize + 1);
5064 void tst_QWidget::update()
5067 QSKIP(
"QTBUG-52974");
5082 QCOMPARE(
w.paintedRegion,
w.visibleRegion());
5089 QPoint childOffset =
child.mapToParent(QPoint());
5100 QCOMPARE(
w.paintedRegion,
child.visibleRegion().translated(childOffset));
5113 QCOMPARE(
w.paintedRegion,
w.visibleRegion());
5116 QPalette opaquePalette =
child.palette();
5117 opaquePalette.setColor(
child.backgroundRole(), QColor(
Qt::red));
5122 child.setPalette(opaquePalette);
5123 child.setAutoFillBackground(
true);
5135 -
child.visibleRegion().translated(childOffset);
5136 QCOMPARE(
w.visibleRegion(), expectedVisible);
5137 QCOMPARE(
w.paintedRegion, expectedVisible);
5158 sibling.setGeometry(15, 15, 20, 20);
5166 const QPoint siblingOffset = sibling.mapToParent(QPoint());
5174 QCOMPARE(sibling.numPaintEvents, 1);
5175 QCOMPARE(sibling.paintedRegion, sibling.visibleRegion());
5179 child.visibleRegion().translated(childOffset)
5180 & sibling.visibleRegion().translated(siblingOffset));
5184 w.visibleRegion() & sibling.visibleRegion().translated(siblingOffset));
5186 (
w.visibleRegion() -
child.visibleRegion().translated(childOffset))
5187 & sibling.visibleRegion().translated(siblingOffset));
5194 sibling.setPalette(opaquePalette);
5195 sibling.setAutoFillBackground(
true);
5203 QCOMPARE(sibling.numPaintEvents, 1);
5204 QCOMPARE(sibling.paintedRegion, sibling.visibleRegion());
5207 if (
child.internalWinId())
5213 - sibling.visibleRegion().
translated(siblingOffset - childOffset));
5218 -
child.visibleRegion().translated(childOffset)
5219 - sibling.visibleRegion().translated(siblingOffset));
5224 static inline bool isOpaque(QWidget *
widget)
5232 void tst_QWidget::isOpaque()
5241 child.setAutoFillBackground(
true);
5249 palette.setColor(
child.backgroundRole(), QColor(255, 0, 0, 127));
5253 palette.setColor(
child.backgroundRole(), QColor(255, 0, 0, 255));
5262 child.setAutoFillBackground(
false);
5298 QVERIFY(!::isOpaque(&widget));
5311 void tst_QWidget::scroll()
5314 QSKIP(
"Wayland: This fails. Figure out why.");
5321 updateWidget.
reset();
5322 updateWidget.
move(m_availableTopLeft);
5329 updateWidget.
reset();
5330 updateWidget.
scroll(10, 10);
5333 dirty +=
QRegion(QRect(0, 10, 10,
h - 10));
5338 updateWidget.
reset();
5339 updateWidget.
update(0, 0, 10, 10);
5340 updateWidget.
scroll(0, 10);
5343 dirty +=
QRegion(QRect(0, 10, 10, 10));
5347 if (updateWidget.
width() < 200 || updateWidget.
height() < 200)
5348 QSKIP(
"Skip this test due to too small screen geometry.");
5351 updateWidget.
reset();
5352 updateWidget.
update(0, 0, 100, 100);
5353 updateWidget.
scroll(10, 10, QRect(50, 50, 100, 100));
5355 QRegion dirty(QRect(0, 0, 100, 50));
5356 dirty +=
QRegion(QRect(0, 50, 150, 10));
5357 dirty +=
QRegion(QRect(0, 60, 110, 40));
5358 dirty +=
QRegion(QRect(50, 100, 60, 10));
5359 dirty +=
QRegion(QRect(50, 110, 10, 40));
5364 updateWidget.
reset();
5365 updateWidget.
update(0, 0, 100, 100);
5366 updateWidget.
scroll(10, 10, QRect(100, 100, 100, 100));
5368 QRegion dirty(QRect(0, 0, 100, 100));
5369 dirty +=
QRegion(QRect(100, 100, 100, 10));
5370 dirty +=
QRegion(QRect(100, 110, 10, 90));
5376 void tst_QWidget::scrollNativeChildren()
5383 const QPoint oldLabelPos(100, 100);
5384 nativeLabel->move(oldLabelPos);
5385 QVERIFY(nativeLabel->winId());
5388 const QPoint delta(50, 50);
5389 parent.scroll(delta.x(), delta.y());
5390 const QPoint newLabelPos = oldLabelPos + delta;
5391 QWindow *labelWindow = nativeLabel->windowHandle();
5393 QTRY_COMPARE(labelWindow->geometry().topLeft(), newLabelPos);
5394 QTRY_COMPARE(nativeLabel->geometry().topLeft(), newLabelPos);
5417 void tst_QWidget::qobject_castInDestroyedSlot()
5434 void tst_QWidget::setWindowGeometry_data()
5436 QTest::addColumn<Rects>(
"rects");
5437 QTest::addColumn<int>(
"windowFlags");
5440 const int width = m_testWidgetSize.width();
5441 const int height = m_testWidgetSize.height();
5443 rects <<
Rects{QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize),
5445 QRect(m_availableTopLeft + QPoint(130, 100), QSize(0,
height)),
5446 QRect(m_availableTopLeft + QPoint(100, 50), QSize(
width, 0)),
5447 QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0))}
5448 <<
Rects{availableAdjusted,
5449 QRect(m_availableTopLeft + QPoint(130, 100), QSize(0,
height)),
5450 QRect(m_availableTopLeft + QPoint(100, 50), QSize(
width, 0)),
5451 QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)),
5452 QRect(m_availableTopLeft + QPoint(100, 100), QSize(
width,
height))}
5453 <<
Rects{QRect(m_availableTopLeft + QPoint(130, 100), QSize(0,
height)),
5454 QRect(m_availableTopLeft + QPoint(100, 50), QSize(
width, 0)),
5455 QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)),
5456 QRect(m_availableTopLeft + QPoint(100, 100), QSize(
width,
height)),
5458 <<
Rects{QRect(m_availableTopLeft + QPoint(100, 50), QSize(
width, 0)),
5459 QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)),
5460 QRect(m_availableTopLeft + QPoint(100, 100), QSize(
width,
height)),
5462 QRect(m_availableTopLeft + QPoint(130, 100), QSize(0,
height))}
5463 <<
Rects{QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)),
5464 QRect(m_availableTopLeft + QPoint(100, 100), QSize(
width,
height)),
5466 QRect(m_availableTopLeft + QPoint(130, 100), QSize(0,
height)),
5467 QRect(m_availableTopLeft + QPoint(100, 50), QSize(
width, 0))};
5471 const bool skipEmptyRects = (m_platform ==
QStringLiteral(
"windows"));
5472 for (
Rects l : qAsConst(rects)) {
5474 l.removeIf([] (
const QRect &
r) {
return r.isEmpty(); });
5475 const QRect &
rect =
l.constFirst();
5476 for (
int windowFlag : windowFlags) {
5482 .arg(windowFlag, 0, 16).toLatin1())
5489 void tst_QWidget::setWindowGeometry()
5492 QSKIP(
"X11: Skip this test due to Window manager positioning issues.");
5495 QFETCH(
int, windowFlags);
5496 QRect
rect = rects.takeFirst();
5501 if (windowFlags != 0)
5509 for (
const QRect &
r : qAsConst(rects)) {
5520 if (windowFlags != 0)
5525 if (
rect.isValid()) {
5535 for (
const QRect &
r : qAsConst(rects)) {
5550 for (
const QRect &
r : qAsConst(rects)) {
5560 QTestPrivate::androidCompatibleShow(&widget);
5575 if (windowFlags != 0)
5586 for (
const QRect &
r : qAsConst(rects)) {
5601 for (
const QRect &
r : qAsConst(rects)) {
5611 QTestPrivate::androidCompatibleShow(&widget);
5624 #if defined (Q_OS_WIN)
5625 void tst_QWidget::setGeometry_win()
5629 setFrameless(&widget);
5630 widget.
setGeometry(QRect(m_availableTopLeft + QPoint(0, 600), QSize(100, 100)));
5639 ::GetWindowRect(winHandleOf(&widget), &
rt);
5641 msgComparisonFailed(
int(
rt.left),
"<=", m_availableTopLeft.x()));
5643 msgComparisonFailed(
int(
rt.top),
"<=", m_availableTopLeft.y()));
5650 void tst_QWidget::windowMoveResize_data()
5652 setWindowGeometry_data();
5655 void tst_QWidget::windowMoveResize()
5658 QSKIP(
"X11: Skip this test due to Window manager positioning issues.");
5660 QSKIP(
"Wayland: This fails. Figure out why.");
5663 QFETCH(
int, windowFlags);
5665 QRect
rect = rects.takeFirst();
5670 if (windowFlags != 0)
5680 for (
const QRect &
r : qAsConst(rects)) {
5693 if (windowFlags != 0)
5704 const bool expectResizeFail = (!windowFlags && (
rect.width() < 160 ||
rect.height() < 40))
5706 if (!expectResizeFail)
5710 for (
const QRect &
r : qAsConst(rects)) {
5712 const bool expectMoveFail = !windowFlags
5715 && (
rect == QRect(QPoint(130, 100), QSize(0, 200))
5716 ||
rect == QRect(QPoint(100, 50), QSize(200, 0))
5717 ||
rect == QRect(QPoint(130, 50), QSize(0, 0)));
5721 if (!expectMoveFail) {
5739 for (
const QRect &
r : qAsConst(rects)) {
5743 #if defined(Q_OS_MACOS)
5744 if (
r.width() == 0 &&
r.height() > 0) {
5759 QTestPrivate::androidCompatibleShow(&widget);
5776 if (windowFlags != 0)
5790 for (
const QRect &
r : qAsConst(rects)) {
5810 for (
const QRect &
r : qAsConst(rects)) {
5814 #if defined(Q_OS_MACOS)
5815 if (
r.width() == 0 &&
r.height() > 0) {
5830 QTestPrivate::androidCompatibleShow(&widget);
5852 QPalette opaquePalette =
palette();
5883 static inline QByteArray msgRgbMismatch(
unsigned actual,
unsigned expected)
5896 #define VERIFY_COLOR(child, region, color) verifyColor(child, region, color, __LINE__)
5903 bool grabBackingStore =
false;
5904 for (QRect
r : region) {
5906 for (
int t = 0;
t < 6;
t++) {
5907 const QPixmap
pixmap = grabBackingStore
5910 const QSize actualSize =
pixmap.size() /
pixmap.devicePixelRatio();
5911 if (!
QTest::qCompare(actualSize,
rect.size(),
"pixmap.size()",
"rect.size()", __FILE__, callerLine))
5913 QPixmap expectedPixmap(
pixmap);
5914 expectedPixmap.detach();
5915 expectedPixmap.fill(
color);
5918 uint firstPixel =
image.pixel(0,0) | alphaCorrection;
5924 if (firstPixel == QColor(
color).
rgb() &&
image == expectedPixmap.toImage())
5927 grabBackingStore =
true;
5935 "firstPixel == QColor(color).rgb()",
5936 qPrintable(msgRgbMismatch(firstPixel, QColor(
color).
rgb())),
5937 __FILE__, callerLine))
5940 "image == expectedPixmap.toImage()",
5941 "grabbed pixmap differs from expected pixmap",
5942 __FILE__, callerLine))
5950 void tst_QWidget::moveChild_data()
5952 QTest::addColumn<QPoint>(
"offset");
5960 void tst_QWidget::moveChild()
5963 QSKIP(
"Wayland: This fails. Figure out why.");
5972 parent.setGeometry(QRect(m_availableTopLeft + QPoint(50, 50), QSize(200, 200)));
5974 #ifndef QT_NO_CURSOR
5987 qApp->processEvents();
6015 void tst_QWidget::showAndMoveChild()
6018 QSKIP(
"Wayland: This fails. Figure out why.");
6025 QRect desktopDimensions =
parent.screen()->availableGeometry();
6026 desktopDimensions = desktopDimensions.adjusted(64, 64, -64, -64);
6028 #ifndef QT_NO_CURSOR
6031 parent.setGeometry(desktopDimensions);
6038 child.resize(desktopDimensions.width()/2, desktopDimensions.height()/2);
6040 child.setAutoFillBackground(
true);
6045 child.move(desktopDimensions.width()/2, desktopDimensions.height()/2);
6053 void tst_QWidget::subtractOpaqueSiblings()
6056 QSKIP(
"QTBUG-52974: Cocoa only has rect granularity.");
6061 w.setGeometry(50, 50, 300, 300);
6091 void tst_QWidget::deleteStyle()
6130 void tst_QWidget::multipleToplevelFocusCheck()
6133 QSKIP(
"QTBUG-52974");
6137 QSKIP(
"Window activation is not supported");
6143 w1.move(m_availableTopLeft + QPoint(20, 20));
6144 w1.resize(200, 200);
6148 w2.move(
w1.frameGeometry().topRight() + QPoint(20, 0));
6154 w1.activateWindow();
6160 w2.activateWindow();
6170 w1.activateWindow();
6177 w2.activateWindow();
6227 void tst_QWidget::setFocus()
6230 QSKIP(
"Window activation is not supported");
6233 testWidget->resize(m_testWidgetSize);
6234 testWidget->setWindowTitle(__FUNCTION__);
6235 centerOnScreen(testWidget.
data());
6239 const QPoint windowPos = testWidget->geometry().topRight() + QPoint(50, 0);
6242 testWidget->activateWindow();
6244 if (testWidget->focusWidget())
6245 testWidget->focusWidget()->clearFocus();
6247 testWidget->clearFocus();
6252 window.resize(m_testWidgetSize);
6276 window.resize(m_testWidgetSize);
6288 testWidget->activateWindow();
6290 if (testWidget->focusWidget())
6291 testWidget->focusWidget()->clearFocus();
6293 testWidget->clearFocus();
6310 window.resize(m_testWidgetSize);
6335 QCOMPARE(child1.widgetDuringFocusAboutToChange, &child1);
6336 QCOMPARE(child1.widgetDuringFocusOut, &child2);
6343 window.resize(m_testWidgetSize);
6384 window.resize(m_testWidgetSize);
6432 window.resize(m_testWidgetSize);
6450 QCOMPARE(child1.focusObjectDuringFocusIn, &child1);
6451 QVERIFY2(!child1.detectedBadEventOrdering,
6452 "focusObjectChanged should be delivered before widget focus events on setFocus");
6459 QVERIFY(child1.focusObjectDuringFocusOut != &child1);
6460 QVERIFY2(!child1.detectedBadEventOrdering,
6461 "focusObjectChanged should be delivered before widget focus events on clearFocus");
6472 m_widget->installEventFilter(
this);
6482 if (
event->type() == eventToSpy)
6493 #ifndef QT_NO_CURSOR
6494 void tst_QWidget::setCursor()
6559 window2.resize(200, 200);
6564 child.setParent(
nullptr);
6568 child.setParent(&window2);
6583 window2.resize(200, 200);
6589 child.setParent(
nullptr);
6593 child.setParent(&window2);
6616 void tst_QWidget::setToolTip()
6619 QSKIP(
"Setting mouse cursor position is not possible on Wayland");
6645 for (
int pass = 0; pass < 2; ++pass) {
6649 popup->setWindowTitle(popup->objectName());
6650 popup->setGeometry(50, 50, 150, 50);
6661 QWindow *popupWindow = popup->windowHandle();
6676 void tst_QWidget::testWindowIconChangeEventPropagation()
6682 topLevelWidget.setWindowTitle(
QStringLiteral(
"TopLevel ") + __FUNCTION__);
6683 topLevelWidget.resize(m_testWidgetSize);
6684 topLevelWidget.move(m_availableTopLeft + QPoint(100, 100));
6685 QWidget topLevelChild(&topLevelWidget);
6687 QDialog
dialog(&topLevelWidget);
6689 dialog.
move(topLevelWidget.geometry().topRight() + QPoint(100, 0));
6694 widgets << &topLevelWidget << &topLevelChild
6695 << &
dialog << &dialogChild;
6698 topLevelWidget.show();
6705 const int lastWidgetWindow = 1;
6723 qApp->setWindowIcon(windowIcon);
6727 EventSpyPtr
spy = applicationEventSpies.
at(
i);
6738 spy = widgetEventSpies.
at(
i);
6745 WindowEventSpyPtr
spy = appWindowEventSpies.
at(
i);
6752 spy = windowEventSpies.
at(
i);
6758 topLevelWidget.setWindowIcon(QIcon());
6762 EventSpyPtr
spy = applicationEventSpies.
at(
i);
6767 spy = widgetEventSpies.
at(
i);
6769 if (widget == &topLevelWidget) {
6772 }
else if (topLevelWidget.isAncestorOf(widget)) {
6781 qApp->setWindowIcon(QIcon());
6784 void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint()
6787 QSKIP(
"This test is for X11 only.");
6790 const QSize originalSize(desktopSize.width() / 2, desktopSize.height() * 4 / 10);
6796 const QSize newMaximumSize =
widget.
size().boundedTo(originalSize) - QSize(10, 10);
6809 const QSize newMinimumSize =
widget.
size().expandedTo(originalSize) + QSize(10, 10);
6847 enum { XCB_MAP_NOTIFY = 19 };
6850 const auto responseType = *
reinterpret_cast<const unsigned char *
>(
message);
6851 return ((responseType & ~0x80) == XCB_MAP_NOTIFY);
6856 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
6868 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
6883 void tst_QWidget::showHideShowX11()
6886 QSKIP(
"This test is for X11 only.");
6890 qApp->installNativeEventFilter(&
w);
6904 void tst_QWidget::clean_qt_x11_enforce_cursor()
6907 QSKIP(
"This test is for X11 only.");
6960 switch (
event->type()) {
6985 void EventRecorder::formatEventList(
const EventList &
l,
QDebug &
d)
6987 QWidget *lastWidget =
nullptr;
6989 if (
p.first != lastWidget) {
6990 d <<
p.first <<
':';
6991 lastWidget =
p.first;
6993 d <<
p.second <<
' ';
7001 d <<
"Event list mismatch, expected " << expected.
size() <<
" (";
7002 EventRecorder::formatEventList(expected,
d);
7003 d <<
"), actual " << actual.
size() <<
" (";
7004 EventRecorder::formatEventList(actual,
d);
7006 return result.toLocal8Bit();
7009 void tst_QWidget::childEvents()
7052 #ifndef Q_OS_ANDROID
7120 child2.setParent(&widget);
7143 #ifndef Q_OS_ANDROID
7176 child2.setParent(&widget);
7177 child2.setParent(
nullptr);
7213 child2.setParent(&widget);
7214 child2.setParent(
nullptr);
7237 #ifndef Q_OS_ANDROID
7281 source->render(
this, QPoint(0, 30), regionToRender);
7292 void tst_QWidget::render()
7310 const QImage sourceImage =
source.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage();
7311 QImage targetImage =
target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage();
7317 target.setEllipseEnabled();
7321 targetImage =
target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage();
7322 QVERIFY(sourceImage != targetImage);
7325 if (targetImage.devicePixelRatioF() > 1)
7331 void tst_QWidget::renderChildFillsBackground()
7345 const QPixmap childPixmap =
child.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
7346 const QPixmap windowPixmap =
window.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
7347 #ifndef Q_OS_ANDROID
7352 QCOMPARE(childPixmap, windowPixmap);
7355 void tst_QWidget::renderTargetOffset()
7389 static void workaroundPaletteIssue(QWidget *
widget)
7400 QPalette
palette = navigationBar->palette();
7405 navigationBar->setPalette(
palette);
7409 void tst_QWidget::renderInvisible()
7412 QSKIP(
"QTBUG-26424");
7429 dummyFocusWidget.
show();
7437 referenceImage.save(
"referenceImage.png");
7439 QVERIFY(!referenceImage.isNull());
7442 const QSize calendarSizeResized =
calendar->
size() + QSize(50, 50);
7448 referenceImageResized.save(
"referenceImageResized.png");
7450 QVERIFY(!referenceImageResized.isNull());
7455 workaroundPaletteIssue(
calendar.data());
7461 testImage.save(
"explicitlyHiddenCalendarResized.png");
7471 workaroundPaletteIssue(
calendar.data());
7477 testImage.save(
"neverBeenVisibleCreatedOrLaidOut.png");
7489 testImage.save(
"explicitlyHiddenCalendar.png");
7497 navigationBar->hide();
7503 testImage.save(
"calendarWithoutNavigationBar.png");
7512 testImage.save(
"explicitlyHiddenNavigationBar.png");
7524 navigationBar->render(&
testImage, QPoint(),
QRegion(), QWidget::RenderFlags());
7526 testImage.save(
"nextMonthButtonBackground.png");
7531 const QPalette originalPalette = nextMonthButton->palette();
7532 QPalette
palette = originalPalette;
7534 nextMonthButton->setPalette(
palette);
7541 const QRect buttonRect(nextMonthButton->mapTo(
calendar.data(), QPoint()), nextMonthButton->size());
7545 nextMonthButton->setPalette(originalPalette);
7549 navigationBar->show();
7577 for (
int i = calendarSize.height();
i < 2 * calendarSize.height(); ++
i)
7578 for (
int j = calendarSize.width();
j < 2 * calendarSize.width(); ++
j)
7585 topLevel.setLayout(
new QVBoxLayout);
7590 const QSize initialSize = topLevel.size();
7591 QPixmap
pixmap(topLevel.sizeHint());
7592 topLevel.render(&
pixmap);
7593 const QSize finalSize = topLevel.size();
7595 msgComparisonFailed(finalSize,
"!=", initialSize));
7597 topLevel.layout()->removeWidget(widget);
7598 QCOMPARE(topLevel.size(), finalSize);
7599 topLevel.render(&
pixmap);
7600 QCOMPARE(topLevel.size(), finalSize);
7602 topLevel.layout()->addWidget(widget);
7603 QCOMPARE(topLevel.size(), finalSize);
7604 topLevel.render(&
pixmap);
7605 QCOMPARE(topLevel.size(), finalSize);
7609 void tst_QWidget::renderWithPainter()
7627 for (
int i = 0;
i <
image.height(); ++
i) {
7628 for (
int j = 0;
j <
image.width(); ++
j)
7639 for (
int i = 0;
i <
image.height(); ++
i) {
7640 for (
int j = 0;
j <
image.width(); ++
j) {
7641 if (
i < 10 ||
j < 10)
7652 for (
int i = 0;
i <
image.height(); ++
i) {
7653 for (
int j = 0;
j <
image.width(); ++
j) {
7654 if (
i < 10 ||
j < 10)
7668 for (
int i = 0;
i <
image.height(); ++
i) {
7669 for (
int j = 0;
j <
image.width(); ++
j) {
7670 if (
i < 20 ||
j < 20)
7684 for (
int i = 0;
i <
image.height(); ++
i) {
7685 for (
int j = 0;
j <
image.width(); ++
j)
7696 for (
int i = 0;
i <
image.height(); ++
i) {
7697 for (
int j = 0;
j <
image.width(); ++
j) {
7698 if (
i >= 10 &&
j >= 0 &&
j < 10)
7708 QPainter::RenderHints oldRenderHints =
painter.renderHints();
7713 void tst_QWidget::render_task188133()
7723 void tst_QWidget::render_task211796()
7738 centerOnScreen(&widget);
7746 centerOnScreen(&widget);
7751 grandChild.
resize(100, 100);
7756 void tst_QWidget::render_task217815()
7764 const QSize explicitSize(80, 20);
7768 QPixmap
pixmap(explicitSize);
7775 void tst_QWidget::render_windowOpacity()
7778 QSKIP(
"Platform offscreen does not support setting opacity");
7780 const qreal opacity = 0.5;
7785 child.resize(50, 50);
7787 child.setAutoFillBackground(
true);
7789 QPixmap expected(
child.size());
7791 if (m_platform ==
QStringLiteral(
"xcb") && expected.depth() < 24)
7792 QSKIP(
"This test won't give correct results with dithered pixmaps");
7821 const qreal opacity;
7835 QPainter pixmapPainter(&
pixmap);
7836 pixmapPainter.setOpacity(opacity);
7851 void tst_QWidget::render_systemClip()
7874 image.save(
"outside_systemclip.png");
7878 for (
int i = 0;
i <
image.height(); ++
i) {
7879 for (
int j = 0;
j <
image.width(); ++
j)
7894 image.save(
"blue_triangle.png");
7907 for (
int i = 0;
i <
image.height(); ++
i) {
7908 for (
int j = 0;
j <
image.width(); ++
j) {
7909 if (
i < 50 &&
j <
i)
7922 const QRegion sysClip(0, 0, 50, 50);
7927 expectedImage.paintEngine()->setSystemClip(sysClip);
7929 QPainter expectedImagePainter(&expectedImage);
7930 expectedImagePainter.setTransform(QTransform().shear(0, 1));
7933 expectedImagePainter.drawPixmap(QPoint(0, 0),
pixmap);
7934 expectedImagePainter.end();
7940 void tst_QWidget::render_systemClip2_data()
7942 QTest::addColumn<bool>(
"autoFillBackground");
7943 QTest::addColumn<bool>(
"usePaintEvent");
7944 QTest::addColumn<QColor>(
"expectedColor");
7951 void tst_QWidget::render_systemClip2()
7953 QFETCH(
bool, autoFillBackground);
7954 QFETCH(
bool, usePaintEvent);
7955 QFETCH(QColor, expectedColor);
7957 QVERIFY2(expectedColor != QColor(
Qt::red),
"Qt::red is the reference color for the image, pick another color");
7962 explicit MyWidget(
bool usePaintEventIn) : usePaintEvent(usePaintEventIn) {}
7963 const bool usePaintEvent;
7977 if (!autoFillBackground)
7988 systemClip +=
QRegion(90, 10, 10, 40);
7995 image.save(
"systemclip_with_device.png");
7999 for (
int i = 0;
i <
image.height(); ++
i) {
8000 for (
int j = 0;
j <
image.width(); ++
j) {
8001 if (systemClip.contains(QPoint(
j,
i)))
8021 image.save(
"systemclip_with_untransformed_painter.png");
8025 for (
int i = 0;
i <
image.height(); ++
i) {
8026 for (
int j = 0;
j <
image.width(); ++
j) {
8027 if (systemClip.contains(QPoint(
j,
i)))
8035 void tst_QWidget::render_systemClip3_data()
8037 QTest::addColumn<QSize>(
"size");
8038 QTest::addColumn<bool>(
"useSystemClip");
8041 QTest::newRow(
"Norwegian Civil Flag") << QSize(220, 160) <<
false;
8042 QTest::newRow(
"Norwegian War Flag") << QSize(270, 160) <<
true;
8047 void tst_QWidget::render_systemClip3()
8050 QFETCH(
bool, useSystemClip);
8054 outerCross -= QRect(0, 0, 60, 60);
8055 outerCross -= QRect(100, 0,
size.width() - 100, 60);
8056 outerCross -= QRect(0, 100, 60, 60);
8057 outerCross -= QRect(100, 100,
size.width() - 100, 60);
8060 innerCross -= QRect(0, 0, 70, 70);
8061 innerCross -= QRect(90, 0,
size.width() - 90, 70);
8062 innerCross -= QRect(0, 90, 70, 70);
8063 innerCross -= QRect(90, 90,
size.width() - 90, 70);
8066 const QRegion whiteArea(outerCross - innerCross);
8073 if (useSystemClip) {
8075 warClip.lineTo(
size.width() - 110, 60);
8076 warClip.lineTo(
size.width(), 80);
8077 warClip.lineTo(
size.width() - 110, 100);
8078 warClip.lineTo(
size.width(), 160);
8079 warClip.closeSubpath();
8081 flag.paintEngine()->setSystemClip(systemClip);
8086 painter.setClipRegion(outerCross);
8108 widget.clip = innerCross;
8115 flag.save(
"flag.png");
8119 for (
int i = 0;
i < flag.height(); ++
i) {
8120 for (
int j = 0;
j < flag.width(); ++
j) {
8121 const QPoint pixel(
j,
i);
8122 const QRgb pixelValue = flag.pixel(pixel);
8123 if (useSystemClip && !systemClip.
contains(pixel))
8125 else if (redArea.contains(pixel))
8127 else if (whiteArea.contains(pixel))
8135 void tst_QWidget::render_task252837()
8146 void tst_QWidget::render_worldTransform()
8158 const QPoint widgetOffset = geometry().topLeft();
8160 expectedDeviceTransform.rotate(90);
8161 expectedDeviceTransform.translate(widgetOffset.x(), widgetOffset.y());
8166 newWorldTransform.rotate(90);
8167 painter.setWorldTransform(newWorldTransform);
8171 expectedDeviceTransform.translate(10, 10);
8172 expectedDeviceTransform.rotate(90);
8185 child.setParent(&widget);
8187 child.setFixedSize(50, 50);
8189 child.setAutoFillBackground(
true);
8201 image.save(
"render_worldTransform_image.png");
8213 QPainter expectedPainter(&expected);
8214 expectedPainter.translate(105, 5);
8215 expectedPainter.rotate(90);
8216 expectedPainter.save();
8218 expectedPainter.translate(10, 10);
8219 expectedPainter.rotate(90);
8220 expectedPainter.fillRect(QRect(0, 0, 20, 10),
Qt::green);
8221 expectedPainter.restore();
8222 expectedPainter.translate(50, 50);
8224 expectedPainter.translate(10, 10);
8225 expectedPainter.rotate(90);
8226 expectedPainter.fillRect(QRect(0, 0, 20, 10),
Qt::green);
8227 expectedPainter.end();
8230 expected.save(
"render_worldTransform_expected.png");
8236 void tst_QWidget::setContentsMargins()
8238 QLabel
label(
"why does it always rain on me?");
8239 QSize oldSize =
label.sizeHint();
8241 QSize newSize =
label.sizeHint();
8242 QVERIFY2(oldSize != newSize, msgComparisonFailed(oldSize,
"!=", newSize));
8244 QLabel label2(
"why does it always rain on me?");
8248 QCOMPARE(newSize, label2.sizeHint());
8250 QLabel label3(
"why does it always rain on me?");
8252 QCOMPARE(newSize, label3.sizeHint());
8255 void tst_QWidget::moveWindowInShowEvent_data()
8257 QTest::addColumn<QPoint>(
"initial");
8258 QTest::addColumn<QPoint>(
"position");
8260 QPoint
p = m_availableTopLeft;
8266 void tst_QWidget::moveWindowInShowEvent()
8269 QSKIP(
"QTBUG-26424");
8274 class MoveWindowInShowEventWidget :
public QWidget
8284 MoveWindowInShowEventWidget
widget;
8301 void tst_QWidget::repaintWhenChildDeleted()
8305 const QPoint startPoint = m_availableTopLeft + QPoint(50, 50);
8306 w.setGeometry(QRect(startPoint, QSize(100, 100)));
8324 void tst_QWidget::hideOpaqueChildWhileHidden()
8328 const QPoint startPoint = m_availableTopLeft + QPoint(50, 50);
8329 w.setGeometry(QRect(startPoint, QSize(100, 100)));
8335 child2.setGeometry(10, 10, 60, 60);
8347 qApp->processEvents();
8366 void tst_QWidget::updateWhileMinimized()
8369 QSKIP(
"Wayland: This fails. Figure out why.");
8371 QSKIP(
"Platform offscreen does not support showMinimized()");
8373 #if defined(Q_OS_QNX)
8374 QSKIP(
"Platform does not support showMinimized()");
8379 widget.updateOnActivationChangeAndFocusIn =
false;
8400 const QString desktop = qgetenv(
"XDG_CURRENT_DESKTOP");
8401 qDebug() <<
"xcb: XDG_CURRENT_DESKTOP=" << desktop;
8420 #if defined(Q_OS_WIN)
8422 QPaintEngine *paintEngine()
const override {
return nullptr; }
8426 void tst_QWidget::alienWidgets()
8429 QSKIP(
"This test is only for X11/Windows.");
8434 parent.resize(m_testWidgetSize);
8437 QWidget greatGrandChild(&grandChild);
8454 QVERIFY(!greatGrandChild.internalWinId());
8460 QVERIFY(greatGrandChild.internalWinId());
8469 window.resize(m_testWidgetSize);
8487 QWidget paintOnScreenChild(&paintOnScreen);
8488 paintOnScreen.show();
8491 QVERIFY(!paintOnScreen.internalWinId());
8493 QVERIFY(!paintOnScreenChild.internalWinId());
8501 QVERIFY(paintOnScreen.internalWinId());
8507 QVERIFY(paintOnScreenChild.internalWinId());
8513 msWindowsOwnDC.show();
8516 QVERIFY(msWindowsOwnDC.internalWinId());
8532 dummy.resize(m_testWidgetSize);
8542 topLevel.resize(m_testWidgetSize);
8550 QVERIFY(!greatGrandChild.internalWinId());
8561 QVERIFY(greatGrandChild.internalWinId());
8567 topLevel.resize(m_testWidgetSize);
8575 child->setParent(widget);
8577 QVERIFY(!topLevel.internalWinId());
8580 QVERIFY(!grandChild->internalWinId());
8581 QVERIFY(!dummy2->internalWinId());
8584 QVERIFY(topLevel.internalWinId());
8591 QVERIFY(!grandChild->internalWinId());
8593 QVERIFY(!dummy2->internalWinId());
8601 window.resize(m_testWidgetSize);
8605 grandChild.setWindowTitle(
"This causes the widget to be created");
8609 paintOnScreenWidget.setParent(&grandChild);
8611 grandChild.setParent(&
child);
8624 QVERIFY(grandChild.internalWinId());
8630 QVERIFY(paintOnScreenWidget.internalWinId());
8643 centralWidget->setMinimumSize(m_testWidgetSize);
8673 void tst_QWidget::nativeWindowPosition_data()
8675 QTest::addColumn<WidgetAttributes>(
"attributes");
8685 void tst_QWidget::nativeWindowPosition()
8692 grandChild.move(10, 10);
8702 QCOMPARE(grandChild.pos(), QPoint(10, 10));
8712 setWindowTitle(objectName());
8716 sp.setHeightForWidth(hfwLayout);
8718 QVBoxLayout *vbox =
new QVBoxLayout;
8719 vbox->setContentsMargins(0, 0, 0, 0);
8728 return layout()->totalSizeHint();
8739 void tst_QWidget::adjustSize_data()
8741 const int MagicW = 200;
8742 const int MagicH = 100;
8744 QTest::addColumn<QSize>(
"sizeHint");
8745 QTest::addColumn<int>(
"hPolicy");
8746 QTest::addColumn<int>(
"vPolicy");
8747 QTest::addColumn<bool>(
"hfwSP");
8748 QTest::addColumn<bool>(
"layout");
8749 QTest::addColumn<bool>(
"hfwLayout");
8750 QTest::addColumn<bool>(
"haveParent");
8751 QTest::addColumn<QSize>(
"expectedSize");
8754 <<
false <<
false <<
false <<
false << QSize(5, qMax(6, MagicH));
8756 <<
true <<
false <<
false <<
false << QSize(5, qMax(10, MagicH));
8758 <<
false <<
true <<
false <<
false << QSize(35, 26);
8760 <<
false <<
true <<
true <<
false << QSize(35, 70);
8762 <<
false <<
false <<
false <<
false << QSize(100000, 100000);
8764 <<
true <<
false <<
false <<
false << QSize(100000, 100000);
8766 <<
false <<
true <<
false <<
false << QSize(100000, 100000);
8768 <<
false <<
true <<
true <<
false << QSize(100000, 100000);
8770 <<
true <<
false <<
false <<
false << QSize(qMax(5, MagicW), 10);
8773 <<
false <<
false <<
false <<
true << QSize(5, 6);
8775 <<
true <<
false <<
false <<
true << QSize(5, 6 );
8777 <<
false <<
true <<
false <<
true << QSize(35, 26);
8779 <<
false <<
true <<
true <<
true << QSize(35, 70);
8781 <<
false <<
false <<
false <<
true << QSize(40001, 30001);
8783 <<
true <<
false <<
false <<
true << QSize(40001, 30001 );
8785 <<
false <<
true <<
false <<
true << QSize(40001 + 30, 30001 + 20);
8787 <<
false <<
true <<
true <<
true << QSize(40001 + 30, 80002 + 60);
8789 <<
true <<
false <<
false <<
true << QSize(5, 6);
8792 void tst_QWidget::adjustSize()
8800 QFETCH(
bool, haveParent);
8801 QFETCH(QSize, expectedSize);
8806 sp.setHeightForWidth(hfwSP);
8809 child->resize(123, 456);
8810 child->adjustSize();
8811 if (expectedSize == QSize(100000, 100000)) {
8813 msgComparisonFailed(
child->size().width(),
"<", sizeHint.width()));
8815 msgComparisonFailed(
child->size().height(),
"<", sizeHint.height()));
8837 void tst_QWidget::updateGeometry_data()
8839 QTest::addColumn<QSize>(
"minSize");
8840 QTest::addColumn<bool>(
"shouldInvalidate");
8841 QTest::addColumn<QSize>(
"maxSize");
8842 QTest::addColumn<bool>(
"shouldInvalidate2");
8843 QTest::addColumn<QSizePolicy::Policy>(
"verticalSizePolicy");
8844 QTest::addColumn<bool>(
"shouldInvalidate3");
8845 QTest::addColumn<bool>(
"setVisible");
8846 QTest::addColumn<bool>(
"shouldInvalidate4");
8849 << QSize(100, 100) <<
true
8855 << QSize(100, 100) <<
true
8858 QTest::newRow(
"setMinimumSize, then maximumSize to a different size")
8859 << QSize(100, 100) <<
true
8860 << QSize(300, 300) <<
true
8863 QTest::newRow(
"setMinimumSize, then maximumSize to the same size")
8864 << QSize(100, 100) <<
true
8865 << QSize(100, 100) <<
true
8868 QTest::newRow(
"setMinimumSize, then maximumSize to the same size and then hide it")
8869 << QSize(100, 100) <<
true
8870 << QSize(100, 100) <<
true
8881 void tst_QWidget::updateGeometry()
8884 QFETCH(
bool, shouldInvalidate);
8886 QFETCH(
bool, shouldInvalidate2);
8888 QFETCH(
bool, shouldInvalidate3);
8889 QFETCH(
bool, setVisible);
8890 QFETCH(
bool, shouldInvalidate4);
8898 lout->addWidget(
child);
8903 if (minSize.isValid())
8904 child->setMinimumSize(minSize);
8908 if (maxSize.isValid())
8909 child->setMaximumSize(maxSize);
8914 if (shouldInvalidate3)
8919 child->setVisible(
false);
8923 void tst_QWidget::sendUpdateRequestImmediately()
8927 updateWidget.
show();
8932 updateWidget.
reset();
8939 void tst_QWidget::doubleRepaint()
8942 QSKIP(
"QTBUG-52974");
8945 #if defined(Q_OS_MACOS)
8946 if (!macHasAccessToWindowsServer())
8947 QSKIP(
"Not having window server access causes the wrong number of repaints to be issues");
8951 centerOnScreen(&widget);
8954 widget.updateOnActivationChangeAndFocusIn =
false;
8957 int expectedRepaints = 1;
8961 widget.numPaintEvents = 0;
8967 widget.numPaintEvents = 0;
8976 void tst_QWidget::resizeInPaintEvent()
8990 widget.resizeInPaintEvent =
true;
8998 void tst_QWidget::opaqueChildren()
9008 grandChild.resize(200, 200);
9010 QWidget greatGrandChild(&grandChild);
9011 greatGrandChild.setGeometry(50, 50, 200, 200);
9012 greatGrandChild.setPalette(
Qt::red);
9013 greatGrandChild.setAutoFillBackground(
true);
9019 QRegion expectedOpaqueRegion(50, 50, 150, 150);
9028 greatGrandChild.setMask(
mask);
9029 expectedOpaqueRegion &=
mask.translated(50, 50);
9033 greatGrandChild.setAutoFillBackground(
false);
9048 for (
const QRect &
r :
event->region())
9064 void resizeUp() { setGeometry(QRect(0, 50, 150, 50)); }
9067 void tst_QWidget::setMaskInResizeEvent()
9078 testWidget.setGeometry(0, 0, 100, 100);
9079 testWidget.setMask(
QRegion(QRect(0,0,100,10)));
9086 testWidget.paintedRegion =
QRegion();
9087 testWidget.resizeDown();
9089 QRegion expectedParentUpdate(0, 0, 100, 10);
9090 expectedParentUpdate += testWidget.geometry();
9093 QTRY_COMPARE(testWidget.paintedRegion, testWidget.mask());
9095 testWidget.paintedRegion =
QRegion();
9096 testWidget.repainted =
false;
9098 testWidget.resizeUp();
9100 QTRY_COMPARE(testWidget.paintedRegion, testWidget.mask());
9115 move(QPoint(100,100));
9117 static bool firstTime =
true;
9130 void tst_QWidget::moveInResizeEvent()
9134 testWidget.setGeometry(50, 50, 200, 200);
9138 QRect expectedGeometry(100,100, 100, 100);
9142 #ifdef QT_BUILD_INTERNAL
9143 void tst_QWidget::immediateRepaintAfterInvalidateBackingStore()
9146 QSKIP(
"We don't support immediate repaint right after show on other platforms.");
9150 centerOnScreen(
widget.data());
9154 widget->numPaintEvents = 0;
9169 void tst_QWidget::effectiveWinId()
9186 void tst_QWidget::effectiveWinId2()
9207 child.setParent(
nullptr);
9225 void tst_QWidget::customDpi()
9232 topLevel->logicalDpiX();
9236 child->logicalDpiX();
9240 void tst_QWidget::customDpiProperty()
9246 const int initialDpiX = topLevel->logicalDpiX();
9247 const int initialDpiY = topLevel->logicalDpiY();
9249 middle->setProperty(
"_q_customDpiX", 300);
9250 middle->setProperty(
"_q_customDpiY", 400);
9252 QCOMPARE(topLevel->logicalDpiX(), initialDpiX);
9253 QCOMPARE(topLevel->logicalDpiY(), initialDpiY);
9255 QCOMPARE(middle->logicalDpiX(), 300);
9256 QCOMPARE(middle->logicalDpiY(), 400);
9261 middle->setProperty(
"_q_customDpiX",
QVariant());
9262 middle->setProperty(
"_q_customDpiY",
QVariant());
9264 QCOMPARE(topLevel->logicalDpiX(), initialDpiX);
9265 QCOMPARE(topLevel->logicalDpiY(), initialDpiY);
9267 QCOMPARE(middle->logicalDpiX(), initialDpiX);
9268 QCOMPARE(middle->logicalDpiY(), initialDpiY);
9274 void tst_QWidget::quitOnCloseAttribute()
9310 void tst_QWidget::moveRect()
9317 child.setUpdatesEnabled(
false);
9324 #if defined(Q_OS_WIN)
9325 class GDIWidget :
public QDialog
9334 QPaintEngine *paintEngine()
const override {
return nullptr; }
9341 const HBRUSH
brush = CreateSolidBrush(RGB(255, 0, 0));
9342 SelectObject(hdc,
brush);
9343 Rectangle(hdc, 0, 0, 10, 10);
9344 DeleteObject(
brush);
9356 QSize sizeHint()
const override {
return {400, 300}; };
9361 const QImage im =
screen->
grabWindow(internalWinId(), 0, 0, -1, -1).toImage();
9362 color = im.pixel(1, 1);
9371 void tst_QWidget::gdiPainting()
9380 void tst_QWidget::paintOnScreenPossible()
9393 void tst_QWidget::reparentStaticWidget()
9396 window1.setWindowTitle(
QStringLiteral(
"window1 ") + __FUNCTION__);
9397 window1.resize(m_testWidgetSize);
9398 window1.move(m_availableTopLeft + QPoint(100, 100));
9402 child->setAutoFillBackground(
true);
9404 child->resize(window1.width() - 40, window1.height() - 40);
9409 grandChild->setAutoFillBackground(
true);
9410 grandChild->resize(50, 50);
9416 window2.setWindowTitle(
QStringLiteral(
"window2 ") + __FUNCTION__);
9417 window2.resize(m_testWidgetSize);
9418 window2.move(window1.geometry().topRight() + QPoint(100, 0));
9423 child->setParent(&window2);
9427 window1.resize(window1.size() + QSize(2, 2));
9433 child->setParent(&window1);
9437 window2.resize(window2.size() + QSize(2, 2));
9440 child->setParent(
nullptr);
9446 window2.resize(window2.size() + QSize(2, 2));
9450 siblingOfGrandChild->show();
9454 grandChild->setParent(siblingOfGrandChild);
9459 paintOnScreen.setWindowTitle(
QStringLiteral(
"paintOnScreen ") + __FUNCTION__);
9460 paintOnScreen.resize(m_testWidgetSize);
9461 paintOnScreen.move(window1.geometry().bottomLeft() + QPoint(0, 50));
9464 paintOnScreen.show();
9468 child->setParent(&paintOnScreen);
9473 paintOnScreen.resize(paintOnScreen.size() + QSize(2, 2));
9478 void tst_QWidget::QTBUG6883_reparentStaticWidget2()
9482 mw.
move(m_availableTopLeft + QPoint(100, 100));
9489 child->setAutoFillBackground(
true);
9491 child->resize(m_testWidgetSize);
9494 QToolBar *mainTools = mw.addToolBar(
"Main Tools");
9496 le->setMinimumWidth(m_testWidgetSize.width());
9522 void tst_QWidget::translucentWidget()
9525 QSKIP(
"Wayland: This fails. Figure out why.");
9531 label.setFixedSize(16,16);
9533 label.move(m_availableTopLeft);
9537 QPixmap widgetSnapshot =
9538 label.grab(QRect(QPoint(0, 0),
label.size()));
9540 QImage expected = pm.toImage().scaled(
label.devicePixelRatio() * pm.size());
9541 expected.setDevicePixelRatio(
label.devicePixelRatio());
9546 QCOMPARE(actual.size(),expected.size());
9567 setMask(
QRegion(QRect(0, 0, 100, 100)));
9575 for (
const QRect &
r :
event->region())
9583 QRegion newMask(QRect(0, 0, 150, 150));
9588 QRegion newMask(QRect(0, 0, 50, 50));
9594 void tst_QWidget::setClearAndResizeMask()
9597 QSKIP(
"Wayland: This fails. Figure out why.");
9601 topLevel.
resize(160, 160);
9602 centerOnScreen(&topLevel);
9611 topLevel.
setMask(topLevelMask);
9625 outsideOldMask -= topLevelMask;
9634 child.setAutoFillBackground(
true);
9636 child.resize(100, 100);
9644 const QRegion childMask(0, 0, 50, 50);
9645 child.setMask(childMask);
9650 if (
child.internalWinId())
9658 expectedParentExpose -= childMask;
9669 outsideOldMask =
child.rect();
9672 if (!
child.internalWinId())
9674 outsideOldMask -= childMask;
9686 if (
child.internalWinId())
9699 if (
child.internalWinId())
9709 resizeParent.resize(300,300);
9710 resizeParent.raise();
9712 resizeChild.setGeometry(50,50,200,200);
9713 QPalette pal = resizeParent.palette();
9715 resizeParent.setPalette(pal);
9717 resizeParent.show();
9720 resizeParent.setFixedSize(resizeParent.size());
9723 resizeChild.paintedRegion =
QRegion();
9729 if (
child.internalWinId())
9730 QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask());
9735 resizeChild.paintedRegion =
QRegion();
9736 const QRegion oldMask = resizeChild.mask();
9741 if (
child.internalWinId())
9742 QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask());
9745 QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask() - oldMask);
9748 void tst_QWidget::maskedUpdate()
9752 topLevel.
resize(200, 200);
9753 centerOnScreen(&topLevel);
9754 const QRegion topLevelMask(50, 50, 70, 70);
9755 topLevel.
setMask(topLevelMask);
9759 const QRegion childMask(60, 60, 30, 30);
9760 child.setMask(childMask);
9763 grandChild.setGeometry(50, 50, 100, 100);
9764 const QRegion grandChildMask(20, 20, 10, 10);
9765 grandChild.setMask(grandChildMask);
9772 #define RESET_WIDGETS \
9777 #define CLEAR_MASK(widget) \
9778 widget.clearMask(); \
9779 QTest::qWait(100); \
9792 QTRY_COMPARE(grandChild.paintedRegion, grandChildMask);
9801 QTRY_COMPARE(grandChild.paintedRegion, grandChildMask);
9805 grandChild.update();
9810 QTRY_COMPARE(grandChild.paintedRegion, grandChildMask);
9824 QRegion expectedTopLevelUpdate = topLevelMask;
9836 QRegion expectedChildUpdate = childMask;
9837 expectedChildUpdate -= grandChildMask.
translated(grandChild.pos());
9843 grandChild.update();
9848 QTRY_COMPARE(grandChild.paintedRegion, grandChildMask);
9852 grandChild.update();
9857 QRegion expectedGrandChildUpdate = grandChild.rect();
9859 expectedGrandChildUpdate &= childMask.
translated(-grandChild.pos());
9860 QCOMPARE(grandChild.paintedRegion, expectedGrandChildUpdate);
9864 grandChild.update();
9869 expectedGrandChildUpdate = grandChild.rect();
9871 expectedGrandChildUpdate &= topLevelMask.
translated(-grandChild.mapTo(&topLevel, QPoint()));
9872 QTRY_COMPARE(grandChild.paintedRegion, expectedGrandChildUpdate);
9880 expectedChildUpdate =
child.rect();
9883 expectedChildUpdate -= grandChild.geometry();
9889 grandChild.update();
9897 #ifndef QT_NO_CURSOR
9898 void tst_QWidget::syntheticEnterLeave()
9901 QSKIP(
"Wayland: This fails. Figure out why.");
9906 void enterEvent(
QEnterEvent *)
override { ++numEnterEvents; }
9907 void leaveEvent(
QEvent *)
override { ++numLeaveEvents; }
9908 int numEnterEvents = 0;
9909 int numLeaveEvents = 0;
9913 if (!QTest::qWaitFor([
this]{
return QCursor::pos() == m_safeCursorPos; }))
9914 QSKIP(
"Can't move cursor");
9925 child1->
resize(200, 200);
9929 child2->
resize(200, 200);
9934 grandChild->
resize(200, 200);
9942 #define RESET_EVENT_COUNTS \
9943 window.numEnterEvents = 0; \
9944 window.numLeaveEvents = 0; \
9945 child1->numEnterEvents = 0; \
9946 child1->numLeaveEvents = 0; \
9947 child2->numEnterEvents = 0; \
9948 child2->numLeaveEvents = 0; \
9949 grandChild->numEnterEvents = 0; \
9950 grandChild->numLeaveEvents = 0;
9953 const QPoint globalPos =
window.mapToGlobal(QPoint(100, 100));
9955 if (!QTest::qWaitFor([globalPos]{
return QCursor::pos() == globalPos; }))
9956 QSKIP(
"Can't move cursor");
9959 QCOMPARE(child2->numLeaveEvents, 0);
9960 QCOMPARE(grandChild->numLeaveEvents, 0);
9961 QCOMPARE(child1->numLeaveEvents, 0);
9965 QCOMPARE(child2->numEnterEvents, 1);
9966 QCOMPARE(grandChild->numEnterEvents, 1);
9967 QCOMPARE(child1->numEnterEvents, 0);
9973 QCOMPARE(child2->numLeaveEvents, 1);
9974 QCOMPARE(grandChild->numLeaveEvents, 1);
9975 QCOMPARE(child1->numLeaveEvents, 0);
9978 QCOMPARE(child2->numEnterEvents, 0);
9979 QCOMPARE(grandChild->numEnterEvents, 0);
9980 QCOMPARE(child1->numEnterEvents, 1);
9986 QCOMPARE(child2->numLeaveEvents, 0);
9987 QCOMPARE(grandChild->numLeaveEvents, 0);
9988 QCOMPARE(child1->numLeaveEvents, 1);
9991 QCOMPARE(child2->numEnterEvents, 1);
9992 QCOMPARE(grandChild->numEnterEvents, 1);
9993 QCOMPARE(child1->numEnterEvents, 0);
9999 QCOMPARE(child1->numLeaveEvents, 0);
10002 QCOMPARE(child1->numEnterEvents, 1);
10006 #ifndef QT_NO_CURSOR
10007 void tst_QWidget::enterLeaveOnWindowShowHide_data()
10009 QTest::addColumn<Qt::WindowType>(
"windowType");
10025 void tst_QWidget::enterLeaveOnWindowShowHide()
10031 int numEnterEvents = 0;
10032 int numLeaveEvents = 0;
10033 QPoint enterPosition;
10038 enterPosition =
e->position().toPoint();
10041 void leaveEvent(
QEvent *)
override
10043 enterPosition = {};
10048 QWidget *secondary =
nullptr;
10049 switch (secondaryWindowType) {
10051 QDialog *
dialog =
new QDialog(
this);
10065 QVERIFY2(
false,
"Test case not implemented for window type");
10069 QPoint secondaryPos =
e->globalPosition().toPoint();
10071 secondaryPos += QPoint(10, 10);
10073 secondaryPos -= QPoint(10, 10);
10074 secondary->move(secondaryPos);
10083 int expectedEnter = 0;
10084 int expectedLeave = 0;
10087 widget.secondaryWindowType = windowType;
10089 const QPoint cursorPos = screenGeometry.topLeft() + QPoint(50, 50);
10090 widget.
setGeometry(QRect(cursorPos - QPoint(50, 50), screenGeometry.size() / 4));
10094 QSKIP(
"We can't move the cursor");
10127 #ifndef QT_NO_CURSOR
10128 void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave()
10131 QSKIP(
"Wayland: Clients can't set cursor position on wayland.");
10132 class SELParent :
public QWidget
10141 class SELChild :
public QWidget
10145 void enterEvent(
QEnterEvent *)
override { ++numEnterEvents; }
10151 ++numMouseMoveEvents;
10153 void reset() { numEnterEvents = numMouseMoveEvents = 0; }
10154 int numEnterEvents = 0, numMouseMoveEvents = 0;
10158 if (!QTest::qWaitFor([
this]{
return QCursor::pos() == m_safeCursorPos; }))
10159 QSKIP(
"Can't move cursor");
10164 parent.resize(200, 200);
10166 child.resize(200, 200);
10170 const QPoint childPos =
child.mapToGlobal(QPoint(100, 100));
10172 if (!QTest::qWaitFor([childPos]{
return QCursor::pos() == childPos; }))
10173 QSKIP(
"Can't move cursor");
10188 child.setMouseTracking(
true);
10219 child.setMouseTracking(
false);
10228 void tst_QWidget::windowFlags()
10231 const auto baseFlags =
w.windowFlags();
10240 void tst_QWidget::initialPosForDontShowOnScreenWidgets()
10243 const QPoint expectedPos(0, 0);
10252 const QPoint expectedPos(100, 100);
10274 void beEvil(QObject *) {
widget->update(0, 0, 150, 150); }
10277 void tst_QWidget::updateOnDestroyedSignal()
10283 child->resize(m_testWidgetSize);
10284 child->setAutoFillBackground(
true);
10295 void tst_QWidget::toplevelLineEditFocus()
10298 QSKIP(
"Wayland: This fails. Figure out why.");
10302 w.setMinimumWidth(m_testWidgetSize.width());
10310 void tst_QWidget::focusWidget_task254563()
10321 container.setFocus();
10327 #ifdef QT_BUILD_INTERNAL
10328 void tst_QWidget::destroyBackingStore()
10332 centerOnScreen(&
w);
10359 #ifdef QT_BUILD_INTERNAL
10367 void tst_QWidget::rectOutsideCoordinatesLimit_task144779()
10369 #ifndef QT_NO_CURSOR
10378 QRect desktopDimensions =
main.screen()->availableGeometry();
10379 QSize mainSize(400, 400);
10380 mainSize = mainSize.boundedTo(desktopDimensions.size());
10381 main.resize(mainSize);
10384 offsetWidget->setGeometry(0, -(15000 - mainSize.height()), mainSize.width(), 15000);
10390 bigWidget->setGeometry(0, 0, mainSize.width(), 50000);
10392 bigWidget->setPalette(
palette);
10393 bigWidget->setAutoFillBackground(
true);
10398 QPixmap correct(
main.size());
10400 const QPixmap mainPixmap = grabFromWidget(&
main, QRect(QPoint(0, 0), QSize(-1, -1)));
10404 #ifndef QT_NO_CURSOR
10409 void tst_QWidget::setGraphicsEffect()
10418 widget->setGraphicsEffect(blurEffect);
10423 widget->setGraphicsEffect(shadowEffect);
10430 anotherWidget->setGraphicsEffect(blurEffect);
10431 widget->setGraphicsEffect(blurEffect);
10432 QVERIFY(!anotherWidget->graphicsEffect());
10438 anotherWidget.reset();
10443 widget->setGraphicsEffect(blurEffect);
10449 widget->setGraphicsEffect(blurEffect);
10450 widget->setGraphicsEffect(
nullptr);
10491 static QImage fillExpected1()
10494 QPainter
p(&expected);
10495 p.fillRect(QRect{{0, 0}, expected.size()}, QBrush(
Qt::gray));
10496 p.fillRect(QRect(10, 10, 10, 10), QBrush(
Qt::red));
10497 p.fillRect(QRect(20, 20, 10, 10), QBrush(
Qt::blue));
10500 static QImage fillExpected2()
10502 QImage expected = fillExpected1();
10503 QPainter
p(&expected);
10510 static QImage fillExpected3()
10522 QPainter
p2(&expected);
10523 p2.fillRect(QRect{{0, 0}, expected.size()},
brush);
10526 static QImage fillExpected4()
10528 QImage expected = fillExpected1();
10538 QPainter
p2(&expected);
10539 p2.fillRect(QRect{{15, 15}, QSize{20, 20}},
brush);
10543 void tst_QWidget::render_graphicsEffect_data()
10545 QTest::addColumn<QImage>(
"expected");
10546 QTest::addColumn<bool>(
"topLevelEffect");
10547 QTest::addColumn<bool>(
"child1Effect");
10548 QTest::addColumn<bool>(
"child2Effect");
10549 QTest::addColumn<int>(
"extent");
10551 QTest::addRow(
"no_effect") << fillExpected1() <<
false <<
false <<
false << 0;
10552 QTest::addRow(
"first_child_effect") << fillExpected2() <<
false <<
true <<
false << 0;
10553 QTest::addRow(
"top_level_effect") << fillExpected3() <<
true <<
false <<
false << 0;
10554 QTest::addRow(
"effect_with_extent") << fillExpected4() <<
false <<
false <<
true << 5;
10557 void tst_QWidget::render_graphicsEffect()
10559 QFETCH(QImage, expected);
10560 QFETCH(
bool, topLevelEffect);
10561 QFETCH(
bool, child1Effect);
10562 QFETCH(
bool, child2Effect);
10567 topLevel->
resize(40, 40);
10578 childWidget1->setAutoFillBackground(
true);
10579 childWidget1->setPalette(
Qt::red);
10580 childWidget1->resize(10, 10);
10581 childWidget1->move(10, 10);
10583 childWidget2->setAutoFillBackground(
true);
10584 childWidget2->setPalette(
Qt::blue);
10585 childWidget2->resize(10, 10);
10586 childWidget2->move(20, 20);
10589 if (topLevelEffect)
10590 topLevel->setGraphicsEffect(graphicsEffect);
10592 childWidget1->setGraphicsEffect(graphicsEffect);
10594 childWidget2->setGraphicsEffect(graphicsEffect);
10595 graphicsEffect->setExtent(extent);
10599 #ifdef RENDER_DEBUG
10606 void tst_QWidget::activateWindow()
10609 QSKIP(
"Window activation is not supported.");
10616 QLabel*
label =
new QLabel(mainwindow.data());
10617 label->setMinimumWidth(m_testWidgetSize.width());
10618 mainwindow->setWindowTitle(
QStringLiteral(
"#1 ") + __FUNCTION__);
10619 mainwindow->setCentralWidget(
label);
10620 mainwindow->move(m_availableTopLeft + QPoint(100, 100));
10621 mainwindow->setVisible(
true);
10622 mainwindow->activateWindow();
10624 QVERIFY(mainwindow->isActiveWindow());
10628 mainwindow2->setWindowTitle(
QStringLiteral(
"#2 ") + __FUNCTION__);
10629 QLabel* label2 =
new QLabel(mainwindow2.data());
10630 label2->setMinimumWidth(m_testWidgetSize.width());
10631 mainwindow2->setCentralWidget(label2);
10632 mainwindow2->move(mainwindow->geometry().bottomLeft() + QPoint(0, 50));
10633 mainwindow2->setVisible(
true);
10634 mainwindow2->activateWindow();
10641 mainwindow->setVisible(
true);
10642 mainwindow->activateWindow();
10649 void tst_QWidget::openModal_taskQTBUG_5804()
10651 #ifdef Q_OS_ANDROID
10652 QSKIP(
"This test hangs on Android");
10667 win->resize(m_testWidgetSize);
10668 win->setWindowTitle(__FUNCTION__);
10669 centerOnScreen(
win.data());
10683 void tst_QWidget::focusProxy()
10694 setFocusProxy(
edit);
10695 QHBoxLayout *
layout =
new QHBoxLayout;
10701 int focusInCount = 0;
10702 int focusOutCount = 0;
10707 if (receiver ==
edit) {
10708 switch (
event->type()) {
10725 container1->edit->setObjectName(
"edit1");
10727 container2->edit->setObjectName(
"edit2");
10729 QHBoxLayout *
layout =
new QHBoxLayout;
10730 layout->addWidget(container1);
10731 layout->addWidget(container2);
10737 QSKIP(
"Window exposed failed");
10739 window.activateWindow();
10741 QSKIP(
"Window activation failed");
10743 if (!QTest::qWaitFor([&]() {
return window.windowHandle()->
isActive(); }, 5000))
10744 QSKIP(
"Window activation failed");
10750 QVERIFY(!container1->hasFocus());
10751 QVERIFY(!container2->hasFocus());
10752 QCOMPARE(container1->focusInCount, 0);
10753 QCOMPARE(container1->focusOutCount, 0);
10756 window.setFocusProxy(container1);
10760 QVERIFY(container1->edit->hasFocus());
10761 QCOMPARE(container1->focusInCount, 1);
10764 window.setFocusProxy(container2);
10768 QCOMPARE(container1->focusOutCount, 0);
10775 QVERIFY(!container1->edit->hasFocus());
10776 QVERIFY(container2->edit->hasFocus());
10777 QCOMPARE(container1->focusInCount, 1);
10778 QCOMPARE(container1->focusOutCount, 1);
10779 QCOMPARE(container2->focusInCount, 1);
10780 QCOMPARE(container2->focusOutCount, 0);
10783 window.setFocusProxy(
nullptr);
10787 QCOMPARE(container1->focusInCount, 1);
10788 QCOMPARE(container1->focusOutCount, 1);
10789 QCOMPARE(container2->focusInCount, 1);
10790 QCOMPARE(container2->focusOutCount, 0);
10793 window.focusWidget()->clearFocus();
10796 QVERIFY(!container2->hasFocus());
10797 QVERIFY(!container2->edit->hasFocus());
10798 QCOMPARE(container2->focusOutCount, 1);
10801 void tst_QWidget::focusProxyAndInputMethods()
10804 QSKIP(
"Window activation is not supported.");
10807 toplevel->resize(200, 200);
10811 child->setFocusProxy(toplevel.data());
10818 QVERIFY(!toplevel->hasFocus());
10824 QVERIFY(toplevel->hasFocus());
10829 #ifdef QT_BUILD_INTERNAL
10830 class scrollWidgetWBS :
public QWidget
10833 void deleteBackingStore()
10835 static_cast<QWidgetPrivate*
>(d_ptr.data())->topData()->repaintManager.reset(
nullptr);
10837 void enableBackingStore()
10849 #ifdef QT_BUILD_INTERNAL
10850 void tst_QWidget::scrollWithoutBackingStore()
10852 scrollWidgetWBS scrollable;
10854 scrollable.resize(200, 200);
10856 child.resize(50,50);
10859 scrollable.scroll(50,50);
10861 scrollable.deleteBackingStore();
10862 scrollable.scroll(-25,-25);
10864 scrollable.enableBackingStore();
10869 void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy()
10876 w.setFocusProxy(
fp);
10882 void tst_QWidget::movedAndResizedAttributes()
10917 w.showFullScreen();
10923 w.move(m_availableTopLeft);
10927 w.resize(m_testWidgetSize);
10932 void tst_QWidget::childAt()
10936 parent.resize(200, 200);
10940 child->setAutoFillBackground(
true);
10945 grandChild->setAutoFillBackground(
true);
10946 grandChild->setGeometry(-20, -20, 220, 220);
10958 child->setMask(QRect(50, 50, 60, 60));
10975 grandChild->setMask(QRect(80, 80, 40, 40));
10990 void tst_QWidget::taskQTBUG_11373()
10992 QSKIP(
"QTBUG-52974");
10999 QCOMPARE(drawer->isVisible(),
false);
11003 QCOMPARE(drawer->isVisible(),
false);
11007 QCOMPARE(drawer->isVisible(),
false);
11012 void tst_QWidget::taskQTBUG_17333_ResizeInfiniteRecursion()
11016 const char *
s =
"border: 1px solid;";
11017 tb.setStyleSheet(
s);
11021 tb.setGeometry(QRect(100, 100, 0, 100));
11025 void tst_QWidget::nativeChildFocus()
11028 QSKIP(
"Wayland: This fails. Figure out why.");
11032 w.setMinimumWidth(m_testWidgetSize.width());
11033 w.setWindowTitle(__FUNCTION__);
11040 p1->setObjectName(
"p1");
11041 p2->setObjectName(
"p2");
11042 centerOnScreen(&
w);
11044 w.activateWindow();
11054 static bool lenientCompare(
const QPixmap &actual,
const QPixmap &expected)
11059 if (expectedImage.size() != actualImage.size()) {
11060 qWarning(
"Image size comparison failed: expected: %dx%d, got %dx%d",
11061 expectedImage.size().width(), expectedImage.size().height(),
11062 actualImage.size().width(), actualImage.size().height());
11066 const int size = actual.width() * actual.height();
11069 auto a =
reinterpret_cast<const QRgb *
>(actualImage.bits());
11070 auto e =
reinterpret_cast<const QRgb *
>(expectedImage.bits());
11071 for (
int i = 0;
i <
size; ++
i) {
11072 const QColor ca(
a[
i]);
11073 const QColor ce(
e[
i]);
11074 if (
qAbs(ca.red() - ce.red()) > threshold
11075 ||
qAbs(ca.green() - ce.green()) > threshold
11076 ||
qAbs(ca.blue() - ce.blue()) > threshold) {
11077 qWarning(
"Color mismatch at pixel #%d: Expected: %d,%d,%d, got %d,%d,%d",
11078 i, ce.red(), ce.green(), ce.blue(), ca.red(), ca.green(), ca.blue());
11086 void tst_QWidget::grab()
11088 for (
int opaque = 0; opaque < 2; ++opaque) {
11094 for (
int col = 0; col <
image.width(); ++col)
11103 QPixmap expected(64, 64);
11107 QPainter
p(&expected);
11108 p.translate(-64, -64);
11109 p.drawTiledPixmap(0, 0, 128, 128, pal.brush(
QPalette::Window).texture(), 0, 0);
11112 QPixmap actual = grabFromWidget(&widget, QRect(64, 64, 64, 64));
11113 QVERIFY(lenientCompare(actual, expected));
11115 actual = grabFromWidget(&widget, QRect(64, 64, -1, -1));
11116 QVERIFY(lenientCompare(actual, expected));
11120 actual = widget2.grab(QRect());
11122 expected = widget2.grab(QRect());
11124 QVERIFY(lenientCompare(actual, expected));
11148 switch (
e->type()) {
11166 void tst_QWidget::grabMouse()
11169 QSKIP(
"Wayland: This fails. Figure out why.");
11175 w.setWindowTitle(
w.objectName());
11177 layout->setContentsMargins(50, 50, 50, 50);
11180 grabber->setObjectName(grabberObjectName);
11181 grabber->setMinimumSize(m_testWidgetSize);
11182 layout->addWidget(grabber);
11183 centerOnScreen(&
w);
11189 QPoint mousePos = QPoint(
w.width() / 2, 10);
11191 grabber->grabMouse();
11192 const int step =
w.height() / 5;
11193 for ( ; mousePos.y() <
w.height() ; mousePos.ry() +=
step) {
11196 const QPoint expectedPos = grabber->mapFromParent(mousePos);
11200 grabber->releaseMouse();
11204 void tst_QWidget::grabKeyboard()
11207 QSKIP(
"Wayland: This fails. Figure out why.");
11212 w.setWindowTitle(
w.objectName());
11216 layout->addWidget(grabber);
11219 layout->addWidget(nonGrabber);
11220 centerOnScreen(&
w);
11226 QTest::keyClick(
w.windowHandle(),
Qt::Key_A);
11254 switch (
e->type()) {
11314 void tst_QWidget::touchEventSynthesizedMouseEvent()
11343 widget.setAcceptTouch(
true);
11365 parent.setAcceptTouch(
true);
11368 child.setAcceptMouse(
false);
11389 const QPoint childPos(5, 5);
11390 child.move(childPos);
11391 child.setAcceptMouse(
false);
11399 const QPoint touchPos(20, 20);
11410 void tst_QWidget::touchCancel()
11414 widget.setAcceptTouch(
true);
11474 void tst_QWidget::touchUpdateOnNewTouch()
11478 widget.setAcceptTouch(
true);
11479 QVBoxLayout *
layout =
new QVBoxLayout;
11511 void tst_QWidget::touchEventsForGesturePendingWidgets()
11550 void tst_QWidget::styleSheetPropagation()
11554 tw.setStyleSheet(
"background-color: red;");
11575 void tst_QWidget::destroyedSignal()
11590 w->blockSignals(
true);
11609 o->blockSignals(
true);
11629 w->blockSignals(
true);
11650 o->blockSignals(
true);
11659 #ifndef QT_NO_CURSOR
11660 void tst_QWidget::underMouse()
11671 topLevelWidget.setObjectName(
"topLevelWidget");
11672 childWidget1.setObjectName(
"childWidget1");
11673 childWidget2.setObjectName(
"childWidget2");
11674 popupWidget.setObjectName(
"popupWidget");
11676 topLevelWidget.setGeometry(100, 100, 300, 300);
11677 childWidget1.setGeometry(20, 20, 100, 100);
11678 childWidget2.setGeometry(20, 120, 100, 100);
11679 popupWidget.setGeometry(50, 100, 50, 50);
11681 topLevelWidget.show();
11685 QPoint outsideWindowPoint(30, -10);
11686 QPoint inWindowPoint(30, 10);
11687 QPoint child1Point(30, 50);
11688 QPoint child2PointA(30, 150);
11689 QPoint child2PointB(31, 151);
11693 QVERIFY(!topLevelWidget.underMouse());
11694 QVERIFY(!childWidget1.underMouse());
11695 QVERIFY(!childWidget2.underMouse());
11701 QVERIFY(topLevelWidget.underMouse());
11702 QVERIFY(!childWidget1.underMouse());
11703 QVERIFY(!childWidget2.underMouse());
11707 QVERIFY(topLevelWidget.underMouse());
11708 QVERIFY(childWidget1.underMouse());
11709 QVERIFY(!childWidget2.underMouse());
11713 QVERIFY(topLevelWidget.underMouse());
11714 QVERIFY(!childWidget1.underMouse());
11715 QVERIFY(childWidget2.underMouse());
11717 topLevelWidget.resetCounts();
11718 childWidget1.resetCounts();
11719 childWidget2.resetCounts();
11720 popupWidget.resetCounts();
11723 popupWidget.show();
11725 QWindow *popupWindow = popupWidget.windowHandle();
11733 QWindowSystemInterface::handleLeaveEvent<QWindowSystemInterface::SynchronousDelivery>(
window);
11737 QVERIFY(!topLevelWidget.underMouse());
11738 QVERIFY(!childWidget1.underMouse());
11739 QVERIFY(!childWidget2.underMouse());
11740 QVERIFY(!popupWidget.underMouse());
11743 QCOMPARE(topLevelWidget.enters, 0);
11744 QCOMPARE(topLevelWidget.leaves, 1);
11749 topLevelWidget.resetCounts();
11750 childWidget2.resetCounts();
11755 QVERIFY(!topLevelWidget.underMouse());
11756 QVERIFY(!childWidget1.underMouse());
11757 QVERIFY(!childWidget2.underMouse());
11758 QVERIFY(!popupWidget.underMouse());
11761 QCOMPARE(topLevelWidget.enters, 0);
11762 QCOMPARE(topLevelWidget.leaves, 0);
11769 QVERIFY(!topLevelWidget.underMouse());
11770 QVERIFY(!childWidget1.underMouse());
11771 QVERIFY(!childWidget2.underMouse());
11772 QVERIFY(!popupWidget.underMouse());
11775 QCOMPARE(topLevelWidget.enters, 0);
11776 QCOMPARE(topLevelWidget.leaves, 0);
11783 QVERIFY(!topLevelWidget.underMouse());
11784 QVERIFY(!childWidget1.underMouse());
11785 QVERIFY(!childWidget2.underMouse());
11786 QVERIFY(!popupWidget.underMouse());
11789 QCOMPARE(topLevelWidget.enters, 0);
11790 QCOMPARE(topLevelWidget.leaves, 0);
11801 const QPoint popupCenter = popupWindow->geometry().center();
11804 QVERIFY(!topLevelWidget.underMouse());
11805 QVERIFY(!childWidget1.underMouse());
11806 QVERIFY(!childWidget2.underMouse());
11807 QVERIFY(popupWidget.underMouse());
11810 QCOMPARE(topLevelWidget.enters, 0);
11811 QCOMPARE(topLevelWidget.leaves, 0);
11816 popupWidget.resetCounts();
11820 QVERIFY(!topLevelWidget.underMouse());
11821 QVERIFY(!childWidget1.underMouse());
11822 QVERIFY(!childWidget2.underMouse());
11823 QVERIFY(popupWidget.underMouse());
11826 QCOMPARE(topLevelWidget.enters, 0);
11827 QCOMPARE(topLevelWidget.leaves, 0);
11837 QVERIFY(!topLevelWidget.underMouse());
11838 QVERIFY(!childWidget1.underMouse());
11839 QVERIFY(!childWidget2.underMouse());
11840 QVERIFY(!popupWidget.underMouse());
11843 QCOMPARE(topLevelWidget.enters, 0);
11844 QCOMPARE(topLevelWidget.leaves, 0);
11857 setGeometry(100, 300, 150, 100);
11859 button->setGeometry(10, 10, 50, 30);
11873 qApp->installEventFilter(
this);
11884 QPoint point1(15, 15);
11885 QPoint point2(15, 20);
11886 QPoint point3(20, 20);
11898 switch (
e->type()) {
11916 void tst_QWidget::taskQTBUG_27643_enterEvents()
11928 button.setGeometry(10, 10, 100, 50);
11933 QPoint overButton(25, 25);
11961 void tst_QWidget::keyboardModifiers()
11965 w.resize(300, 300);
11984 void tst_QWidget::mouseDoubleClickBubbling_QTBUG29680()
11989 parent.resize(200, 200);
11990 child.resize(200, 200);
11999 void tst_QWidget::largerThanScreen_QTBUG30142()
12010 widget2.resize(10000, 400);
12013 QVERIFY2(widget2.frameGeometry().x() >= 0,
12017 void tst_QWidget::resizeStaticContentsChildWidget_QTBUG35282()
12026 childWidget.setGeometry(250, 250, 500, 500);
12030 QCOMPARE(childWidget.numPaintEvents, 0);
12031 childWidget.reset();
12036 QVERIFY2(childWidget.numPaintEvents >= 1,
12037 msgComparisonFailed(childWidget.numPaintEvents,
">=", 1));
12040 void tst_QWidget::qmlSetParentHelper()
12042 #ifdef QT_BUILD_INTERNAL
12052 QSKIP(
"Needs QT_BUILD_INTERNAL");
12056 void tst_QWidget::testForOutsideWSRangeFlag()
12058 QSKIP(
"Test assumes QWindows can have 0x0 size, see QTBUG-61953");
12074 native.resize(0, 0);
12078 QVERIFY(!native.windowHandle()->isExposed());
12088 native.resize(0, 0);
12091 QVERIFY(!native.windowHandle()->isExposed());
12103 QVERIFY(native.windowHandle()->isExposed());
12105 native.resize(0, 0);
12107 QVERIFY(!native.windowHandle()->isExposed());
12137 uid =
event->pointingDevice()->uniqueId().numericId();
12138 switch (
event->type()) {
12160 void tst_QWidget::tabletTracking()
12183 int(
QInputDevice::DeviceType::Stylus),
int(
QPointingDevice::PointerType::Pen),
Qt::NoButton, 0, 0, 0, 0, 0, 0, uid,
Qt::NoModifier);
12188 local += QPoint(10, 10);
12189 deviceLocal += QPoint(10, 10);
12190 deviceGlobal += QPoint(10, 10);
12192 int(
QInputDevice::DeviceType::Stylus),
int(
QPointingDevice::PointerType::Pen),
Qt::NoButton, 0, 0, 0, 0, 0, 0, uid,
Qt::NoModifier);
12201 int(
QInputDevice::DeviceType::Stylus),
int(
QPointingDevice::PointerType::Pen),
Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid,
Qt::NoModifier);
12205 local += QPoint(10, 10);
12206 deviceLocal += QPoint(10, 10);
12207 deviceGlobal += QPoint(10, 10);
12209 int(
QInputDevice::DeviceType::Stylus),
int(
QPointingDevice::PointerType::Pen),
Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid,
Qt::NoModifier);
12214 int(
QInputDevice::DeviceType::Stylus),
int(
QPointingDevice::PointerType::Pen),
Qt::NoButton, 0, 0, 0, 0, 0, 0, uid,
Qt::NoModifier);
12218 local += QPoint(10, 10);
12219 deviceLocal += QPoint(10, 10);
12220 deviceGlobal += QPoint(10, 10);
12222 int(
QInputDevice::DeviceType::Stylus),
int(
QPointingDevice::PointerType::Pen),
Qt::NoButton, 0, 0, 0, 0, 0, 0, uid,
Qt::NoModifier);
12240 void tst_QWidget::closeEvent()
12268 QEXPECT_FAIL(
"",
"Closing a widget without a window will unconditionally send close events",
Continue);
12279 QEXPECT_FAIL(
"",
"Closing a widget without a window will unconditionally send close events",
Continue);
12283 void tst_QWidget::closeWithChildWindow()
12286 auto childWidget =
new QWidget(&widget);
12288 childWidget->windowHandle()->create();
12295 QVERIFY(childWidget->isVisible());
12298 childWidget->hide();
12302 QVERIFY(!childWidget->isVisible());
12331 void tst_QWidget::winIdAfterClose()
12334 auto notifier =
new QObject(widget);
12337 deleteWidget->installEventFilter(
spy);
12394 void tst_QWidget::receivesLanguageChangeEvent()
12407 QVERIFY(
t.load(
"hellotr_la.qm",
":/"));
12412 QCOMPARE(childWidget->languageChangeCount, 1);
12416 void tst_QWidget::receivesApplicationFontChangeEvent()
12430 QFont changedFont = origFont;
12431 changedFont.setPointSize(changedFont.pointSize() + 2);
12437 QCOMPARE(childWidget->applicationFontChangeCount, 0);
12443 void tst_QWidget::receivesApplicationPaletteChangeEvent()
12457 QPalette changedPalette = origPalette;
12464 QCOMPARE(childWidget->applicationPaletteChangeCount, 0);
12480 void tst_QWidget::deleteWindowInCloseEvent()
12482 #ifdef Q_OS_ANDROID
12483 QSKIP(
"This test crashes on Android");
12504 void tst_QWidget::quitOnClose()
12529 void tst_QWidget::setParentChangesFocus_data()
12531 QTest::addColumn<Qt::WindowType>(
"initialType");
12532 QTest::addColumn<bool>(
"initialParent");
12533 QTest::addColumn<Qt::WindowType>(
"targetType");
12534 QTest::addColumn<bool>(
"targetParent");
12535 QTest::addColumn<bool>(
"reparentBeforeShow");
12536 QTest::addColumn<QString>(
"focusWidget");
12538 for (
const bool before : {
true,
false}) {
12539 const char *
tag = before ?
"before" :
"after";
12553 void tst_QWidget::setParentChangesFocus()
12556 QFETCH(
bool, initialParent);
12558 QFETCH(
bool, targetParent);
12559 QFETCH(
bool, reparentBeforeShow);
12563 window.setObjectName(
"window");
12568 std::unique_ptr<QWidget> secondary(
new QWidget(initialParent ? &
window :
nullptr, initialType));
12569 secondary->setObjectName(
"secondary");
12579 if (reparentBeforeShow) {
12580 secondary->setParent(targetParent ? &
window :
nullptr, targetType);
12582 if (secondary->focusWidget())
12583 QCOMPARE(secondary->focusWidget()->objectName(), focusWidget);
12589 if (!reparentBeforeShow) {
12590 secondary->setParent(targetParent ? &
window :
nullptr, targetType);
12598 void tst_QWidget::activateWhileModalHidden()
12617 #ifdef Q_OS_ANDROID
12618 void tst_QWidget::showFullscreenAndroid()
12621 w.setAutoFillBackground(
true);
12622 QPalette
p =
w.palette();
12627 w.showFullScreen();
12631 w.showFullScreen();
12637 const QRect fullGeometry =
w.screen()->geometry();
12639 const QRect grabArea(10, fullGeometry.height() - 30, 20, 20);
12642 QPixmap expectedPix(20, 20);
12651 #include "tst_qwidget.moc"
small capitals from c petite p scientific f u
small capitals from c petite p scientific i
[1]
ChangeEventWindow(QWindow *parent=nullptr)
bool event(QEvent *e) override
int applicationFontChangeCount
int applicationPaletteChangeCount
Composite(QWidget *parent=nullptr, const QString &name=QString())
void paintEvent(QPaintEvent *) override
QSize sizeHint() const override
ContentsPropagationWidget(QWidget *parent=nullptr)
void setContentsPropagation(bool enable)
DestroyTester(QObject *parent=nullptr)
static int parentDestroyed
void parentDestroyedSlot()
void destroyedSlot(QObject *object)
bool eventFilter(QObject *o, QEvent *e) override
EnterTestModalDialog * modal
Q_INVOKABLE QObject(QObject *parent=nullptr)
QPair< QWidget *, QEvent::Type > WidgetEventTypePair
bool eventFilter(QObject *object, QEvent *event) override
static QByteArray msgEventListMismatch(const EventList &expected, const EventList &actual)
EventList eventList() const
static QByteArray msgExpectFailQtBug26424(const EventList &expected, const EventList &actual)
QList< WidgetEventTypePair > EventList
EventSpy(T *widget, QEvent::Type event)
bool eventFilter(QObject *object, QEvent *event) override
static QByteArray msgPointMismatch(const QPoint &p1, const QPoint p2)
static bool fuzzyCompare(const QPoint &p1, const QPoint p2, int fuzz)
MyEvilObject(QWidget *widgetToCrash)
static void(* setWidgetParent)(QObject *, QObject *)
The QAbstractNativeEventFilter class provides an interface for receiving native events,...
The QActionEvent class provides an event that is generated when a QAction is added,...
The QAction class provides an abstraction for user commands that can be added to different user inter...
static void setPalette(const QPalette &, const char *className=nullptr)
static QWidget * widgetAt(const QPoint &p)
static QPalette palette()
static QWidget * activeModalWidget()
static QWidget * focusWidget()
static QWidgetList topLevelWidgets()
static QWidget * activePopupWidget()
static QWidget * activeWindow()
static void setActiveWindow(QWidget *act)
static void setFont(const QFont &, const char *className=nullptr)
The QBitmap class provides monochrome (1-bit depth) pixmaps.
The QBoxLayout class lines up child widgets horizontally or vertically.
The QByteArray class provides an array of bytes.
const char * constData() const noexcept
static QByteArray number(int, int base=10)
qsizetype count(char c) const
The QCloseEvent class contains parameters that describe a close event.
static bool sendEvent(QObject *receiver, QEvent *event)
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
static void setAttribute(Qt::ApplicationAttribute attribute, bool on=true)
[95]
static bool testAttribute(Qt::ApplicationAttribute attribute)
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
static void sendPostedEvents(QObject *receiver=nullptr, int event_type=0)
static void setPos(int x, int y)
static qint64 currentMSecsSinceEpoch() noexcept
The QDebug class provides an output stream for debugging information.
bool eventFilter(QObject *, QEvent *) override
void setModal(bool modal)
The QDoubleSpinBox class provides a spin box widget that takes doubles.
The QEnterEvent class contains parameters that describe an enter event.
The QEvent class is the base class of all event classes. Event objects contain event parameters.
@ ApplicationPaletteChange
@ ApplicationWindowIconChange
The QEventLoop class provides a means of entering and leaving an event loop.
int exec(ProcessEventsFlags flags=AllEvents)
The QFile class provides an interface for reading from and writing to files.
The QFocusEvent class contains event parameters for widget focus events. \inmodule QtGui.
The QFrame class is the base class of widgets that can have a frame.
The QGraphicsBlurEffect class provides a blur effect.
The QGraphicsDropShadowEffect class provides a drop shadow effect.
The QGraphicsEffect class is the base class for all graphics effects.
QGraphicsObject * parent
the parent of the item
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
QGraphicsProxyWidget * addWidget(QWidget *widget, Qt::WindowFlags wFlags=Qt::WindowFlags())
The QGuiApplication class manages the GUI application's control flow and main settings.
static QPlatformNativeInterface * platformNativeInterface()
QScreen * primaryScreen
the primary (or default) screen of the application.
static QObject * focusObject()
void focusObjectChanged(QObject *focusObject)
static QStyleHints * styleHints()
static QWindow * focusWindow()
static Qt::KeyboardModifiers keyboardModifiers()
static void setOverrideCursor(const QCursor &)
static void restoreOverrideCursor()
QString platformName
The name of the underlying platform plugin.
static QList< QScreen * > screens()
static Qt::MouseButtons mouseButtons()
static QPlatformIntegration * platformIntegration()
The QHideEvent class provides an event which is sent after a widget is hidden.
@ Format_ARGB32_Premultiplied
The QKeyEvent class describes a key event.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
The QLayout class is the base class of geometry managers.
void addWidget(QWidget *w)
QLayout * layout() override
virtual QRect geometry() const =0
virtual void setGeometry(const QRect &)=0
The QLineEdit widget is a one-line text editor.
QString text
the line edit's text.
qsizetype size() const noexcept
QList< T > & fill(parameter_type t, qsizetype size=-1)
const_reference at(qsizetype i) const noexcept
qsizetype count() const noexcept
void append(parameter_type t)
The QMainWindow class provides a main application window.\inmodule QtWidgets.
bool qFuzzyCompare(const QMatrix4x4 &m1, const QMatrix4x4 &m2)
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
The QMouseEvent class contains parameters that describe a mouse event.
Q_INVOKABLE QObject(QObject *parent=nullptr)
T findChild(const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
void installEventFilter(QObject *filterObj)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
QString objectName
the name of this object
virtual bool event(QEvent *event)
virtual bool eventFilter(QObject *watched, QEvent *event)
void setObjectName(const QString &name)
void destroyed(QObject *=nullptr)
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
void setSystemClip(const QRegion &baseClip)
QRegion systemClip() const
The QPaintEvent class contains event parameters for paint events. \inmodule QtGui.
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
The QPen class defines how a QPainter should draw lines and outlines of shapes.
static int defaultDepth()
The QPointF class defines a point in the plane using floating point precision.
constexpr QPoint toPoint() const
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
The QPolygon class provides a list of points using integer precision. \inmodule QtGui.
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
double bounded(double highest)
The QRectF class defines a finite rectangle in the plane using floating point precision.
constexpr qreal y() const noexcept
constexpr qreal height() const noexcept
constexpr qreal width() const noexcept
constexpr qreal x() const noexcept
The QRegion class specifies a clip region for a painter.
bool contains(const QPoint &p) const
QRegion translated(int dx, int dy) const
The QRegularExpression class provides pattern matching using regular expressions.
The QResizeEvent class contains event parameters for resize events. \inmodule QtGui.
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
T * data() const noexcept
The QScreen class is used to query screen properties. \inmodule QtGui.
QRect availableGeometry
the screen's available geometry in pixels
QRect geometry
the screen's geometry in pixels
QPixmap grabWindow(WId window=0, int x=0, int y=0, int w=-1, int h=-1)
QSize size
the pixel resolution of the screen
QSize availableSize
the screen's available size in pixels
The QSharedPointer class holds a strong reference to a shared pointer.
The QShowEvent class provides an event that is sent when a widget is shown.
Qt::MouseButtons buttons() const
The QSizeF class defines the size of a two-dimensional object using floating point precision.
The QString class provides a Unicode character string.
QByteArray toLatin1() const &
QString toLower() const &
static QString number(int, int base=10)
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
The QStringList class provides a list of strings.
static QStyle * create(const QString &)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
@ SH_ToolTip_FallAsleepDelay
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
The QTableView class provides a default model/view implementation of a table view.
QTouchEventSequence & move(int touchId, const QPoint &pt, QWindow *window=nullptr)
QTouchEventSequence & press(int touchId, const QPoint &pt, QWindow *window=nullptr)
QTouchEventSequence & release(int touchId, const QPoint &pt, QWindow *window=nullptr)
virtual QTouchEventSequence & stationary(int touchId)
The QTimerEvent class contains parameters that describe a timer event.
The QTimer class provides repetitive and single-shot timers.
void setSingleShot(bool singleShot)
void setInterval(int msec)
bool singleShot
whether the timer is a single-shot timer
void timeout(QPrivateSignal)
The QTouchEvent class contains parameters that describe a touch event.
The QTranslator class provides internationalization support for text output.
The QTreeView class provides a default model/view implementation of a tree view.
The QVariant class acts like a union for the most common Qt data types.
The QWindow class represents a window in the underlying windowing system.
virtual bool event(QEvent *) override
static bool handleTabletEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, const QPointF &local, const QPointF &global, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
static bool handleTouchCancelEvent(QWindow *window, const QPointingDevice *device, Qt::KeyboardModifiers mods=Qt::NoModifier)
static void handleEnterEvent(QWindow *window, const QPointF &local=QPointF(), const QPointF &global=QPointF())
SiblingDeleter(QWidget *sibling, QWidget *parent)
TestGraphicsEffect(QObject *parent=nullptr)
void setExtent(int extent)
void draw(QPainter *painter) override
QRectF boundingRectFor(const QRectF &sr) const override
void invalidate() override
void mouseDoubleClickEvent(QMouseEvent *) override
TopLevelFocusCheck(QWidget *parent=nullptr)
bool eventFilter(QObject *obj, QEvent *event) override
bool eventFilter(QObject *obj, QEvent *event) override
WinIdChangeSpy(QWidget *w, QObject *parent=nullptr)
object setObjectName("A new object name")
QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)))
[0]
QRhiTextureRenderTarget * rt
QList< QWindow * > windows
std::string toLower(std::string const &s)
bool testImage(const QImage &img, QByteArray *msg, bool *error)
T toNativePixels(const T &value, const C *context)
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
T toNativeLocalPosition(const T &value, const C *context)
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
bool qCompare(QString const &t1, QLatin1String const &t2, const char *actual, const char *expected, const char *file, int line)
Q_TESTLIB_EXPORT bool qVerify(bool statement, const char *statementStr, const char *description, const char *file, int line)
Q_TESTLIB_EXPORT const char * currentTestFunction()
Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType=QInputDevice::DeviceType::TouchScreen, QInputDevice::Capabilities caps=QInputDevice::Capability::Position)
Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, int timeout=5000)
Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout=5000)
void mouseMove(QWindow *window, QPoint pos=QPoint(), int delay=-1)
Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const char *message)
void mouseDClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
Q_TESTLIB_EXPORT const char * currentDataTag()
void mouseClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
Q_TESTLIB_EXPORT QTestData & addRow(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
void mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
Q_CORE_EXPORT void qWait(int ms)
QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit=true)
@ WA_WState_ExplicitShowHide
@ WA_TransparentForMouseEvents
@ WA_TranslucentBackground
@ WA_X11NetWmWindowTypeToolBar
@ WA_DontCreateNativeAncestors
@ AA_DontCreateNativeWidgetSiblings
QTextStream & center(QTextStream &stream)
@ X11BypassWindowManagerHint
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QByteArrayView haystack, QByteArrayView needle) noexcept
const char * sizePolicy(int v)
MyMainWidget * mainWindow
MyMainWidget mySession(nullptr)
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld cleanup[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
set set set set set set set macro pixldst1 op
png_structrp int png_fixed_point red
#define QByteArrayLiteral(str)
std::pair< T1, T2 > QPair
EGLOutputLayerEXT EGLint attribute
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
bool qFuzzyIsNull(qfloat16 f) noexcept
QT_END_INCLUDE_NAMESPACE typedef double qreal
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLenum GLuint GLenum GLsizei const GLchar * message
GLint GLfloat GLfloat GLfloat v2
GLboolean GLboolean GLboolean b
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLuint GLsizei const GLchar * label
[43]
GLenum GLuint GLintptr offset
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
GLuint GLenum GLenum transform
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
GLuint GLuint GLuint GLuint arg1
GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg3
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLenum GLenum GLsizei void * row
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr QRgb qRgba(int r, int g, int b, int a)
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
#define QStringLiteral(str)
#define QTEST_MAIN(TestObject)
#define QSKIP(statement,...)
#define QFETCH(Type, name)
#define QTRY_COMPARE_WITH_TIMEOUT(expr, expected, timeout)
#define QEXPECT_FAIL(dataIndex, comment, mode)
#define QTRY_COMPARE(expr, expected)
#define QVERIFY(statement)
#define QTRY_VERIFY(expr)
#define QVERIFY2(statement, description)
#define QTRY_VERIFY2(expr, messageExpression)
const char className[16]
[1]
QPropertyAnimation * animation
[0]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
obj metaObject() -> className()
QList< QWidget * > widgets
[11]
QFileDialog dialog(this)
[1]
item setCursor(Qt::IBeamCursor)
[1]
view viewport() -> scroll(dx, dy, deviceRect)
app setAttribute(Qt::AA_DontShowIconsInMenus)
backaction setToolTip(browser.historyTitle(-1))
[0]
bool eventFilter(QObject *receiver, QEvent *event) override
WindowStateChangeWatcher(QWidget *widget)
Qt::WindowStates lastWindowStates
QThreadStorage< int * > dummy[8]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
XmlOutput::xml_output tag(const QString &name)