/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
** This file is part of the test suite of the Qt Toolkit.
**
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qstyle.h>
#include <qwidget.h>
#include <qwindowsstyle.h>
-#include <qinputcontext.h>
#include <qdesktopwidget.h>
#include <private/qwidget_p.h>
#include <private/qapplication_p.h>
#include <QtGui/qpaintengine.h>
#include <QtGui/qbackingstore.h>
#include <QtGui/qguiapplication.h>
+#include <QtGui/qscreen.h>
#include <qmenubar.h>
+#include <qcompleter.h>
#include <qtableview.h>
+#include <qtreewidget.h>
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QGraphicsProxyWidget>
-#ifdef Q_WS_QWS
-# include <qscreen_qws.h>
-#endif
-
-// I *MUST* have QtTest afterwards or this test won't work with newer headers
-#if defined(Q_WS_MAC)
-# include <private/qt_mac_p.h>
-#undef verify
+#if defined(Q_OS_MAC)
#include "tst_qwidget_mac_helpers.h" // Abstract the ObjC stuff out so not everyone must run an ObjC++ compile.
#endif
#include <QtTest/QtTest>
-#if defined(Q_OS_WIN)
+#ifdef Q_OS_WIN
# include <QtCore/qt_windows.h>
# include <QtGui/private/qguiapplication_p.h>
-# include <QtGui/QPlatformNativeInterface>
-# include <QtGui/QPlatformIntegration>
+#include <qpa/qplatformnativeinterface.h>
+#include <qpa/qplatformintegration.h>
static HWND winHandleOf(const QWidget *w)
{
qWarning() << "Cannot obtain native handle for " << w;
return 0;
}
-#endif
-#if defined(Q_WS_WIN)
-# include <qt_windows.h>
-# if !defined(Q_OS_WINCE)
-#define Q_CHECK_PAINTEVENTS \
+# ifdef Q_OS_WINCE
+# define Q_CHECK_PAINTEVENTS
+# ifdef Q_OS_WINCE_WM
+# include <qguifunctions_wince.h>
+// taken from qguifunctions_wce.cpp
+# define SPI_GETPLATFORMTYPE 257
+static bool qt_wince_is_platform(const QString &platformString) {
+ wchar_t tszPlatform[64];
+ if (SystemParametersInfo(SPI_GETPLATFORMTYPE,
+ sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0))
+ if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (platformString.utf16()), tszPlatform))
+ return true;
+ return false;
+}
+static inline bool qt_wince_is_smartphone() { return qt_wince_is_platform(QString::fromLatin1("Smartphone")); }
+# endif // Q_OS_WINCE_WM
+# else // Q_OS_WINCE
+# define Q_CHECK_PAINTEVENTS \
if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \
QSKIP("desktop is not visible, this test would fail");
-# else
-# define Q_CHECK_PAINTEVENTS
-# endif
-#elif defined(Q_WS_X11)
-# include <private/qt_x11_p.h>
-# include <qx11info_x11.h>
-#elif defined(Q_WS_QWS)
-# include <qwindowsystem_qws.h>
-#endif
+# endif // !Q_OS_WINCE
+#else // Q_OS_WIN
+# define Q_CHECK_PAINTEVENTS
+#endif // else Q_OS_WIN
-#if !defined(Q_WS_WIN)
-#define Q_CHECK_PAINTEVENTS
-#endif
#if defined(Q_OS_WINCE_WM)
#include <qguifunctions_wince.h>
}
#endif
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
#include <Security/AuthSession.h>
bool macHasAccessToWindowsServer()
{
}
#endif
-
-#if defined(Bool)
-#undef Bool
-#endif
-
class tst_QWidget : public QObject
{
Q_OBJECT
void palettePropagation();
void palettePropagation2();
void enabledPropagation();
+ void popupEnterLeave();
#ifndef QT_NO_DRAGANDDROP
void acceptDropsPropagation();
#endif
void focusChainOnHide();
void focusChainOnReparent();
void setTabOrder();
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
void activation();
#endif
void reparent();
-#ifndef Q_WS_X11
void windowState();
-#endif
void showMaximized();
void showFullScreen();
void showMinimized();
void showMinimizedKeepsFocus();
-#ifndef Q_WS_QWS
void icon();
-#endif
void hideWhenFocusWidgetIsChild();
-#ifndef Q_OS_IRIX
void normalGeometry();
-#endif
void setGeometry();
#ifndef Q_OS_WINCE
void windowOpacity();
void stackUnder();
#endif
void testContentsPropagation();
-#ifndef Q_OS_IRIX
void saveRestoreGeometry();
void restoreVersion1Geometry_data();
void restoreVersion1Geometry();
-#endif
void widgetAt();
-#ifdef Q_WS_MAC
- void retainHIView();
+#ifdef Q_OS_MAC
void sheetOpacity();
void setMask();
#endif
void update();
void isOpaque();
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
void scroll();
#endif
-#ifndef Q_WS_X11
// tests QWidget::setGeometry()
void setWindowGeometry_data();
void setWindowGeometry();
-#endif
-#if !defined(Q_WS_X11) && !defined(Q_OS_IRIX)
// tests QWidget::move() and resize()
void windowMoveResize_data();
void windowMoveResize();
-#endif
void moveChild_data();
void moveChild();
void subtractOpaqueSiblings();
#endif
-#ifdef Q_WS_WIN
- void getDC();
-#ifndef Q_OS_WINCE
+#if defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
void setGeometry_win();
#endif
-#endif
void setLocale();
void deleteStyle();
void setCursor();
void setToolTip();
void testWindowIconChangeEventPropagation();
-#ifdef Q_WS_X11
+
void minAndMaxSizeWithX11BypassWindowManagerHint();
- void showHideShow();
+ void showHideShowX11();
void clean_qt_x11_enforce_cursor();
-#endif
- void compatibilityChildInsertedEvents();
+ void childEvents();
void render();
void renderInvisible();
void renderWithPainter();
void setContentsMargins();
-#ifndef Q_OS_IRIX
void moveWindowInShowEvent_data();
void moveWindowInShowEvent();
-#endif
void repaintWhenChildDeleted();
void hideOpaqueChildWhileHidden();
-#if !defined(Q_OS_WINCE) && !defined(Q_WS_QWS)
+#if !defined(Q_OS_WINCE)
void updateWhileMinimized();
#endif
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
void alienWidgets();
-#endif
void adjustSize();
void adjustSize_data();
void updateGeometry();
void updateGeometry_data();
void sendUpdateRequestImmediately();
-#ifndef Q_OS_IRIX
void doubleRepaint();
-#endif
-#ifndef Q_WS_MAC
void resizeInPaintEvent();
void opaqueChildren();
-#endif
void setMaskInResizeEvent();
void moveInResizeEvent();
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
- // We don't support immediate repaint right after show on
- // other platforms. Must be compatible with Qt 4.3.
void immediateRepaintAfterShow();
void immediateRepaintAfterInvalidateBuffer();
-#endif
+
void effectiveWinId();
void effectiveWinId2();
void customDpi();
void quitOnCloseAttribute();
void moveRect();
-#if defined (Q_WS_WIN)
+#if defined (Q_OS_WIN)
void gdiPainting();
void paintOnScreenPossible();
#endif
void reparentStaticWidget();
void QTBUG6883_reparentStaticWidget2();
-#ifdef Q_WS_QWS
- void updateOutsideSurfaceClip();
-#endif
+
void translucentWidget();
void setClearAndResizeMask();
#endif
void windowFlags();
void initialPosForDontShowOnScreenWidgets();
-#ifdef Q_WS_X11
- void paintOutsidePaintEvent();
-#endif
void updateOnDestroyedSignal();
void toplevelLineEditFocus();
void inputFocus_task257832();
void taskQTBUG_7532_tabOrderWithFocusProxy();
void movedAndResizedAttributes();
void childAt();
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
void childAt_unifiedToolBar();
void taskQTBUG_11373();
#endif
void taskQTBUG_17333_ResizeInfiniteRecursion();
void nativeChildFocus();
+ void grab();
private:
bool ensureScreenSize(int width, int height);
QWidget *testWidget;
+
+ const QString m_platform;
};
bool tst_QWidget::ensureScreenSize(int width, int height)
{
QSize available;
-#ifdef Q_WS_QWS
- available = QDesktopWidget().availableGeometry().size();
- if (available.width() < width || available.height() < height) {
- QScreen *screen = QScreen::instance();
- if (!screen)
- return false;
- screen->setMode(width, height, screen->depth());
- }
-#endif // Q_WS_QWS
-
available = QDesktopWidget().availableGeometry().size();
return (available.width() >= width && available.height() >= height);
}
-class MyInputContext : public QInputContext
-{
-public:
- MyInputContext() : QInputContext() {}
- QString identifierName() { return QString("NoName"); }
- QString language() { return QString("NoLanguage"); }
- void reset() {}
- bool isComposing() const { return false; }
-};
-
// Testing get/set functions
void tst_QWidget::getSetCheck()
{
obj1.setMinimumWidth(INT_MIN);
QCOMPARE(obj1.minimumWidth(), 0); // A widgets width can never be less than 0
obj1.setMinimumWidth(INT_MAX);
-#ifndef Q_WS_QWS //QWS doesn't allow toplevels to be bigger than the screen
- QCOMPARE(obj1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium
-#endif
child1.setMinimumWidth(0);
QCOMPARE(child1.minimumWidth(), 0);
obj1.setMinimumHeight(INT_MIN);
QCOMPARE(obj1.minimumHeight(), 0); // A widgets height can never be less than 0
obj1.setMinimumHeight(INT_MAX);
-#ifndef Q_WS_QWS //QWS doesn't allow toplevels to be bigger than the screen
- QCOMPARE(obj1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium
-#endif
child1.setMinimumHeight(0);
QCOMPARE(child1.minimumHeight(), 0);
obj1.setAcceptDrops(true);
QCOMPARE(true, obj1.acceptDrops());
- // QInputContext * QWidget::inputContext()
- MyInputContext *var13 = new MyInputContext;
- qApp->setInputContext(var13);
- QCOMPARE((QInputContext *)0, obj1.inputContext()); // The widget by default doesn't have the WA_InputMethodEnabled attribute
- obj1.setAttribute(Qt::WA_InputMethodEnabled);
- QCOMPARE(static_cast<QInputContext *>(var13), obj1.inputContext());
-
// bool QWidget::autoFillBackground()
// void QWidget::setAutoFillBackground(bool)
obj1.setAutoFillBackground(false);
QCOMPARE(true, obj1.autoFillBackground());
delete var1;
-#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
- HWND handle = obj1.winId();
- long flags = GetWindowLong(handle, GWL_STYLE);
- QVERIFY(flags & WS_POPUP);
+ const HWND handle = reinterpret_cast<HWND>(obj1.winId()); // explicitly create window handle
+ QVERIFY(GetWindowLong(handle, GWL_STYLE) & WS_POPUP);
#endif
}
-tst_QWidget::tst_QWidget()
+tst_QWidget::tst_QWidget() : m_platform(qApp->platformName().toLower())
{
QFont font;
font.setBold(true);
/* Write number of vertices */
painter.setPen( Qt::red );
- painter.setFont( QFont("Helvetica", 14, QFont::DemiBold, TRUE ) );
+ painter.setFont( QFont("Helvetica", 14, QFont::DemiBold, true ) );
QString caption;
caption.setNum( bezier.size() );
caption += QString::fromLatin1( " vertices" );
childWidget->show();
QCOMPARE( font, childWidget->font() );
- font.setBold( TRUE );
+ font.setBold( true );
testWidget->setFont( font );
QCOMPARE( font, testWidget->font() );
QCOMPARE( font, childWidget->font() );
QFont newFont = font;
- newFont.setItalic( TRUE );
+ newFont.setItalic( true );
childWidget->setFont( newFont );
QWidget* grandChildWidget = new QWidget( childWidget );
QCOMPARE( font, testWidget->font() );
QCOMPARE( newFont, grandChildWidget->font() );
- font.setUnderline( TRUE );
+ font.setUnderline( true );
testWidget->setFont( font );
// the child and grand child should now have merged bold and
// underline
- newFont.setUnderline( TRUE );
+ newFont.setUnderline( true );
QCOMPARE( newFont, childWidget->font() );
QCOMPARE( newFont, grandChildWidget->font() );
QVERIFY( testWidget->isEnabled() );
QVERIFY( childWidget->isEnabled() );
- testWidget->setEnabled( FALSE );
+ testWidget->setEnabled( false );
QVERIFY( !testWidget->isEnabled() );
QVERIFY( !childWidget->isEnabled() );
- testWidget->setDisabled( FALSE );
+ testWidget->setDisabled( false );
QVERIFY( testWidget->isEnabled() );
QVERIFY( childWidget->isEnabled() );
QWidget* grandChildWidget = new QWidget( childWidget );
QVERIFY( grandChildWidget->isEnabled() );
- testWidget->setDisabled( TRUE );
+ testWidget->setDisabled( true );
QVERIFY( !testWidget->isEnabled() );
QVERIFY( !childWidget->isEnabled() );
QVERIFY( !grandChildWidget->isEnabled() );
- grandChildWidget->setEnabled( FALSE );
- testWidget->setEnabled( TRUE );
+ grandChildWidget->setEnabled( false );
+ testWidget->setEnabled( true );
QVERIFY( testWidget->isEnabled() );
QVERIFY( childWidget->isEnabled() );
QVERIFY( !grandChildWidget->isEnabled() );
- grandChildWidget->setEnabled( TRUE );
- testWidget->setEnabled( FALSE );
- childWidget->setDisabled( TRUE );
- testWidget->setEnabled( TRUE );
+ grandChildWidget->setEnabled( true );
+ testWidget->setEnabled( false );
+ childWidget->setDisabled( true );
+ testWidget->setEnabled( true );
QVERIFY( testWidget->isEnabled() );
QVERIFY( !childWidget->isEnabled() );
QVERIFY( !grandChildWidget->isEnabled() );
QVERIFY( childWidget->isEnabledTo( testWidget ) );
QVERIFY( grandChildWidget->isEnabledTo( testWidget ) );
- childWidget->setEnabled( FALSE );
+ childWidget->setEnabled( false );
QVERIFY( !childWidget->isEnabledTo( testWidget ) );
QVERIFY( grandChildWidget->isEnabledTo( childWidget ) );
QVERIFY( !grandChildWidget->isEnabledTo( testWidget ) );
QVERIFY( !testWidget->isVisible() );
testWidget->setWindowOpacity(0.5);
#ifdef Q_OS_WIN
- QVERIFY(::IsWindowVisible(winHandleOf(testWidget)) == FALSE);
+ QVERIFY(!::IsWindowVisible(winHandleOf(testWidget)));
#endif
testWidget->setWindowOpacity(1.0);
}
void tab()
{
- focusNextPrevChild(TRUE);
+ focusNextPrevChild(true);
}
void backTab()
{
- focusNextPrevChild(FALSE);
+ focusNextPrevChild(false);
}
};
container.show();
container.activateWindow();
qApp->setActiveWindow(&container);
-#ifdef Q_WS_X11
- QTest::qWaitForWindowShown(&container);
- QTest::qWait(50);
-#endif
-
+ QTest::qWaitForWindowShown(container.windowHandle());
QTest::qWait(100);
QTRY_VERIFY(lastEdit->hasFocus());
QVERIFY(firstEdit->hasFocus());
}
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
void tst_QWidget::activation()
{
Q_CHECK_PAINTEVENTS
QVERIFY(qApp->activeWindow() == &widget1);
widget2.showNormal();
QTest::qWait(waitTime);
-#if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
+#ifndef Q_OS_WINCE
if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
QEXPECT_FAIL("", "MS introduced new behavior after XP", Continue);
#endif
QTest::qWait(waitTime);
QVERIFY(qApp->activeWindow() == &widget1);
}
-#endif
+#endif // Q_OS_WIN
-// Many window managers do not support window state properly, which causes this test to fail.
-#ifndef Q_WS_X11
void tst_QWidget::windowState()
{
+ if (m_platform == QStringLiteral("xcb"))
+ QSKIP("X11: Many window managers do not support window state properly, which causes this test to fail.");
#ifdef Q_OS_WINCE_WM
QPoint pos(500, 500);
QSize size(200, 200);
QTRY_COMPARE(widget1.pos(), pos);
QTRY_COMPARE(widget1.size(), size);
}
-#endif
void tst_QWidget::showMaximized()
{
window.showMinimized();
QTest::qWait(30);
QTRY_VERIFY(window.isMinimized());
-#ifdef Q_WS_QWS
- QEXPECT_FAIL("", "QWS does not implement showMinimized()", Continue);
-#endif
QCOMPARE(window.focusWidget(), static_cast<QWidget*>(0));
-#ifdef Q_WS_QWS
- QEXPECT_FAIL("", "QWS does not implement showMinimized()", Continue);
-#endif
QTRY_COMPARE(qApp->focusWidget(), static_cast<QWidget*>(0));
window.showNormal();
qApp->setActiveWindow(&window);
QTest::qWaitForWindowShown(&window);
QTest::qWait(30);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
if (!macHasAccessToWindowsServer())
QEXPECT_FAIL("", "When not having WindowServer access, we lose focus.", Continue);
#endif
QTRY_COMPARE(window.focusWidget(), firstchild);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
if (!macHasAccessToWindowsServer())
QEXPECT_FAIL("", "When not having WindowServer access, we lose focus.", Continue);
#endif
child.setGeometry(childPos.x(), childPos.y(), child.width(), child.height());
child.show();
-#ifdef Q_WS_X11
- // On X11, the window manager will apply NorthWestGravity rules to 'child', which
- // means the top-left corner of the window frame will be placed at 'childPos',
- // causing this test to fail
-#else
+ if (m_platform == QStringLiteral("xcb"))
+ QEXPECT_FAIL("", "On X11, the window manager will apply NorthWestGravity rules to 'child', which"
+ " means the top-left corner of the window frame will be placed at 'childPos'"
+ " causing this test to fail.", Continue);
+
QCOMPARE(child.geometry().topLeft(), childPos);
-#endif
QTRY_COMPARE(childTLW.pos(), tlwPos);
-
- // This following part of the test only makes sense on Windows.
-#ifdef Q_WS_WIN
- QWidget childTLWChild(&childTLW);
- childTLWChild.setObjectName("childTLWChild");
-
- QWidget grandChild(&child);
- grandChild.setObjectName("grandChild");
- grandChild.setGeometry(10, 10, 160, 110);
- QPalette pal3;
- pal3.setColor(grandChild.backgroundRole(), Qt::red);
- grandChild.setPalette(pal3);
- //grandChild.setPaletteBackgroundColor(Qt::red);
-
- QWidget grandChildTLW(&grandChild, Qt::Window);
- grandChildTLW.setObjectName("grandChildTLW");
- grandChildTLW.setGeometry(200, 200, 50, 50);
- QPalette pal4;
- pal4.setColor(grandChildTLW.backgroundRole(), Qt::yellow);
- grandChildTLW.setPalette(pal4);
- //grandChildTLW.setPaletteBackgroundColor(Qt::yellow);
-
- QWidget grandChildTLWChild(&grandChildTLW);
- grandChildTLWChild.setObjectName("grandChildTLWChild");
-
- QVERIFY(IsWindow(childTLW.winId()));
- QVERIFY(IsWindow(childTLWChild.winId()));
- QVERIFY(IsWindow(grandChildTLW.winId()));
- QVERIFY(IsWindow(grandChildTLWChild.winId()));
-
- parent.show();
-
- QVERIFY(IsWindow(childTLW.winId()));
- QVERIFY(IsWindow(childTLWChild.winId()));
- QVERIFY(IsWindow(grandChildTLW.winId()));
- QVERIFY(IsWindow(grandChildTLWChild.winId()));
-
- child.setParent(&parent);
- child.move(10,10);
- child.show();
-
- // this appears to stabelize results
- qApp->processEvents();
-
- QVERIFY(IsWindow(childTLW.winId()));
- QVERIFY(IsWindow(childTLWChild.winId()));
-
- QVERIFY(IsWindow(grandChildTLW.winId()));
- QVERIFY(IsWindow(grandChildTLWChild.winId()));
-#endif
}
// Qt/Embedded does it differently.
-#ifndef Q_WS_QWS
void tst_QWidget::icon()
{
QPixmap p(20,20);
testWidget->showNormal();
QVERIFY(!testWidget->windowIcon().isNull());
}
-#endif
void tst_QWidget::hideWhenFocusWidgetIsChild()
{
edit->setFocus();
qApp->processEvents();
QString actualFocusWidget, expectedFocusWidget;
-#ifdef Q_WS_X11
- if (!qApp->focusWidget())
- QSKIP("Your window manager is too broken for this test");
-#endif
+ if (!qApp->focusWidget() && m_platform == QStringLiteral("xcb"))
+ QSKIP("X11: Your window manager is too broken for this test");
+
QVERIFY(qApp->focusWidget());
actualFocusWidget.sprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className());
expectedFocusWidget.sprintf("%p %s %s", edit, edit->objectName().toLatin1().constData(), edit->metaObject()->className());
delete parentWidget;
}
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
void tst_QWidget::normalGeometry()
{
QWidget parent;
QTest::qWait(10);
QTRY_COMPARE(parent.normalGeometry(), geom);
}
-#endif
void tst_QWidget::setGeometry()
{
void tst_QWidget::lostUpdatesOnHide()
{
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
UpdateWidget widget;
widget.setAttribute(Qt::WA_DontShowOnScreen);
widget.show();
parent->show();
QTest::qWaitForWindowShown(parent);
QTest::qWait(10);
-#ifdef Q_WS_QWS
- QApplication::sendPostedEvents(); //glib workaround
-#endif
-
QList<QObject *> list1;
list1 << child1 << child2 << child3 << child4;
QVERIFY(parent->children() == list1);
foreach (UpdateWidget *child, allChildren) {
int expectedPaintEvents = child == child4 ? 1 : 0;
-#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
+#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
if (expectedPaintEvents == 1 && child->numPaintEvents == 2)
QEXPECT_FAIL(0, "Mac and Windows issues double repaints for Z-Order change", Continue);
#endif
#ifdef Q_OS_WINCE
qApp->processEvents();
#endif
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
QEXPECT_FAIL(0, "See QTBUG-493", Continue);
#endif
QCOMPARE(child->numPaintEvents, 0);
void tst_QWidget::testContentsPropagation()
{
ContentsPropagationWidget widget;
-#ifdef Q_WS_QWS
- widget.resize(500,500);
-#else
widget.setFixedSize(500, 500);
-#endif
widget.setContentsPropagation(false);
- QPixmap widgetSnapshot = QPixmap::grabWidget(&widget);
+ QPixmap widgetSnapshot = widget.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
QPixmap correct(500, 500);
drawPolygon(&correct, 500, 500);
QVERIFY(widgetSnapshot.toImage() != correct.toImage());
widget.setContentsPropagation(true);
- widgetSnapshot = QPixmap::grabWidget(&widget);
+ widgetSnapshot = widgetSnapshot = widget.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
//widgetSnapshot.save("snap2.png", "PNG");
QCOMPARE(widgetSnapshot, correct);
Test that saving and restoring window geometry with
saveGeometry() and restoreGeometry() works.
*/
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
+
void tst_QWidget::saveRestoreGeometry()
{
const QPoint position(100, 100);
QTRY_COMPARE(widget.geometry(), geom);
}
}
-#endif
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
void tst_QWidget::restoreVersion1Geometry_data()
{
QTest::addColumn<QString>("fileName");
widgetToSave.move(expectedPosition);
widgetToSave.resize(expectedSize);
widgetToSave.show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&widget);
-#endif
+ QTest::qWaitForWindowShown(widget.windowHandle());
QTest::qWait(500); // stabilize
widgetToSave.setWindowState(Qt::WindowStates(expectedWindowState));
QTest::qWait(500); // stabilize
}
#endif
}
-#endif
void tst_QWidget::widgetAt()
{
#if defined(Q_OS_WINCE)
QEXPECT_FAIL("", "Windows CE does only support rectangular regions", Continue); //See also task 147191
#endif
- /// ### fixme: Check platforms
- QEXPECT_FAIL("", "Window mask not implemented on Lighthouse QTBUG-22326", Continue);
+ if (!QGuiApplication::platformName().compare(QLatin1String("cocoa"), Qt::CaseInsensitive))
+ QEXPECT_FAIL("", "Window mask not implemented on Mac QTBUG-22326", Continue);
- QTRY_COMPARE(QApplication::widgetAt(100,100)->objectName(), w1->objectName());
- QTRY_COMPARE(QApplication::widgetAt(101,101)->objectName(), w2->objectName());
+ QTRY_VERIFY((wr = QApplication::widgetAt(100,100)));
+ QTRY_COMPARE(wr->objectName(), w1->objectName());
+ QTRY_VERIFY((wr = QApplication::widgetAt(101,101)));
+ QTRY_COMPARE(wr->objectName(), w2->objectName());
QBitmap bitmap(w2->size());
QPainter p(&bitmap);
#if defined(Q_OS_WINCE)
QEXPECT_FAIL("", "Windows CE does only support rectangular regions", Continue); //See also task 147191
#endif
- /// ### fixme: Check platforms
- QEXPECT_FAIL("", "Window mask not implemented on Lighthouse QTBUG-22326", Continue);
+ if (!QGuiApplication::platformName().compare(QLatin1String("cocoa"), Qt::CaseInsensitive))
+ QEXPECT_FAIL("", "Window mask not implemented on Mac QTBUG-22326", Continue);
QTRY_VERIFY(QApplication::widgetAt(100,100) == w1);
QTRY_VERIFY(QApplication::widgetAt(101,101) == w2);
delete w1;
}
-#if defined(Q_WS_X11)
-bool getProperty(Display *display, Window target, Atom type, Atom property,
- unsigned char** data, unsigned long* count)
-{
- Atom atom_return;
- int size;
- unsigned long nitems, bytes_left;
-
- int ret = XGetWindowProperty(display, target, property,
- 0l, 1l, false,
- type, &atom_return, &size,
- &nitems, &bytes_left, data);
- if (ret != Success || nitems < 1)
- return false;
-
- if (bytes_left != 0) {
- XFree(*data);
- unsigned long remain = ((size / 8) * nitems) + bytes_left;
- ret = XGetWindowProperty(display, target,
- property, 0l, remain, false,
- type, &atom_return, &size,
- &nitems, &bytes_left, data);
- if (ret != Success)
- return false;
- }
-
- *count = nitems;
- return true;
-}
-
-QString textPropertyToString(Display *display, XTextProperty& text_prop)
-{
- QString ret;
- if (text_prop.value && text_prop.nitems > 0) {
- if (text_prop.encoding == XA_STRING) {
- ret = reinterpret_cast<char *>(text_prop.value);
- } else {
- text_prop.nitems = strlen(reinterpret_cast<char *>(text_prop.value));
- char **list;
- int num;
- if (XmbTextPropertyToTextList(display, &text_prop, &list, &num) == Success
- && num > 0 && *list) {
- ret = QString::fromLocal8Bit(*list);
- XFreeStringList(list);
- }
- }
- }
- return ret;
-}
-#endif
-
void tst_QWidget::task110173()
{
QWidget w;
delete w;
}
-#ifdef Q_WS_MAC
-
-/*
- Test that retaining and releasing the HIView returned by QWidget::winId()
- works even if the widget itself is deleted.
-*/
-void tst_QWidget::retainHIView()
-{
- // Single window
- {
- const WidgetViewPair window = createAndRetain();
- delete window.first;
- QVERIFY(testAndRelease(window.second));
- }
-
- // Child widget
- {
- const WidgetViewPair parent = createAndRetain();
- const WidgetViewPair child = createAndRetain(parent.first);
-
- delete parent.first;
- QVERIFY(testAndRelease(parent.second));
- QVERIFY(testAndRelease(child.second));
- }
-
- // Multiple children
- {
- const WidgetViewPair parent = createAndRetain();
- const WidgetViewPair child1 = createAndRetain(parent.first);
- const WidgetViewPair child2 = createAndRetain(parent.first);
-
- delete parent.first;
- QVERIFY(testAndRelease(parent.second));
- QVERIFY(testAndRelease(child1.second));
- QVERIFY(testAndRelease(child2.second));
- }
-
- // Grandchild widget
- {
- const WidgetViewPair parent = createAndRetain();
- const WidgetViewPair child = createAndRetain(parent.first);
- const WidgetViewPair grandchild = createAndRetain(child.first);
-
- delete parent.first;
- QVERIFY(testAndRelease(parent.second));
- QVERIFY(testAndRelease(child.second));
- QVERIFY(testAndRelease(grandchild.second));
- }
-
- // Reparent child widget
- {
- const WidgetViewPair parent1 = createAndRetain();
- const WidgetViewPair parent2 = createAndRetain();
- const WidgetViewPair child = createAndRetain(parent1.first);
-
- child.first->setParent(parent2.first);
-
- delete parent1.first;
- QVERIFY(testAndRelease(parent1.second));
- delete parent2.first;
- QVERIFY(testAndRelease(parent2.second));
- QVERIFY(testAndRelease(child.second));
- }
-
- // Reparent window
- {
- const WidgetViewPair window1 = createAndRetain();
- const WidgetViewPair window2 = createAndRetain();
- const WidgetViewPair child1 = createAndRetain(window1.first);
- const WidgetViewPair child2 = createAndRetain(window2.first);
-
- window2.first->setParent(window1.first);
-
- delete window2.first;
- QVERIFY(testAndRelease(window2.second));
- QVERIFY(testAndRelease(child2.second));
- delete window1.first;
- QVERIFY(testAndRelease(window1.second));
- QVERIFY(testAndRelease(child1.second));
- }
-
- // Delete child widget
- {
- const WidgetViewPair parent = createAndRetain();
- const WidgetViewPair child = createAndRetain(parent.first);
-
- delete child.first;
- QVERIFY(testAndRelease(child.second));
- delete parent.first;
- QVERIFY(testAndRelease(parent.second));
- }
-}
-
+#ifdef Q_OS_MAC
void tst_QWidget::sheetOpacity()
{
QWidget tmpWindow;
*/
bool verifyWidgetMask(QWidget *widget, QRect mask)
{
- const QImage image = QPixmap::grabWindow(widget->winId()).toImage();
+ const QImage image = widget->grab(QRect(QPoint(0, 0), widget->size())).toImage();
const QImage masked = image.copy(mask);
QImage red(masked);
void tst_QWidget::optimizedResize_topLevel()
{
-#if defined(Q_WS_MAC) || defined(Q_WS_QWS)
+#if defined(Q_OS_MAC)
QSKIP("We do not yet have static contents support for *top-levels* on this platform");
#endif
topLevel.partial = false;
topLevel.paintedRegion = QRegion();
-#ifndef Q_WS_WIN
+#ifndef Q_OS_WIN
topLevel.resize(topLevel.size() + QSize(10, 10));
#else
// Static contents does not work when programmatically resizing
// WM_RESIZE in QApplication). This is a corner case, though.
// See task 243708
const QRect frame = topLevel.frameGeometry();
- MoveWindow(topLevel.winId(), frame.x(), frame.y(),
+ MoveWindow(winHandleOf(&topLevel), frame.x(), frame.y(),
frame.width() + 10, frame.height() + 10,
true);
#endif
}
-#ifdef Q_WS_QWS
-# define SET_SAFE_SIZE(w) \
- do { \
- QSize safeSize(qt_screen->width() - 250, qt_screen->height() - 250); \
- if (!safeSize.isValid()) \
- QSKIP("Screen size too small"); \
- if (defaultSize.width() > safeSize.width() || defaultSize.height() > safeSize.height()) { \
- defaultSize = safeSize; \
- w.resize(defaultSize); \
- w.setAttribute(Qt::WA_Resized, false); \
- } \
- } while (false)
-#else
-# define SET_SAFE_SIZE(w)
-#endif
-
-
void tst_QWidget::setMinimumSize()
{
QWidget w;
QSize defaultSize = w.size();
- SET_SAFE_SIZE(w);
w.setMinimumSize(defaultSize + QSize(100, 100));
QCOMPARE(w.size(), defaultSize + QSize(100, 100));
{
QWidget w;
QSize defaultSize = w.size();
- SET_SAFE_SIZE(w);
w.setMinimumSize(defaultSize + QSize(100, 100));
QCOMPARE(w.size(), defaultSize + QSize(100, 100));
{
QWidget w;
QSize defaultSize = w.size();
- SET_SAFE_SIZE(w);
w.setFixedSize(defaultSize + QSize(100, 100));
QCOMPARE(w.size(), defaultSize + QSize(100, 100));
void tst_QWidget::isOpaque()
{
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
QWidget w;
QVERIFY(::isOpaque(&w));
#endif
}
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
/*
Test that scrolling of a widget invalidates the correct regions
*/
// Since X11 WindowManager operations are all async, and we have no way to know if the window
// manager has finished playing with the window geometry, this test can't be reliable on X11.
-#ifndef Q_WS_X11
+
void tst_QWidget::setWindowGeometry_data()
{
QTest::addColumn<QList<QRect> >("rects");
.arg(rect.y())
.arg(rect.width())
.arg(rect.height())
- .arg(windowFlag, 0, 16).toAscii())
+ .arg(windowFlag, 0, 16).toLatin1())
<< l
<< windowFlag;
}
void tst_QWidget::setWindowGeometry()
{
+ if (m_platform == QStringLiteral("xcb"))
+ QSKIP("X11: Skip this test due to Window manager positioning issues.");
+
QFETCH(QList<QRect>, rects);
QFETCH(int, windowFlags);
QRect rect = rects.takeFirst();
QTRY_COMPARE(widget.geometry(), rect);
}
}
-#endif
-#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE)
+#if defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
void tst_QWidget::setGeometry_win()
{
QWidget widget;
widget.setWindowState(widget.windowState() | Qt::WindowMaximized);
widget.show();
RECT rt;
- ::GetWindowRect(widget.internalWinId(), &rt);
+ ::GetWindowRect(winHandleOf(&widget), &rt);
QVERIFY(rt.left <= 0);
QVERIFY(rt.top <= 0);
}
-#endif
+#endif // defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
// Since X11 WindowManager operation are all async, and we have no way to know if the window
// manager has finished playing with the window geometry, this test can't be reliable on X11.
-// 4DWM issues on IRIX also makes this test fail.
-#if !defined(Q_WS_X11) && !defined(Q_OS_IRIX)
+
void tst_QWidget::windowMoveResize_data()
{
setWindowGeometry_data();
void tst_QWidget::windowMoveResize()
{
+ if (m_platform == QStringLiteral("xcb"))
+ QSKIP("X11: Skip this test due to Window manager positioning issues.");
+
QFETCH(QList<QRect>, rects);
QFETCH(int, windowFlags);
QTRY_COMPARE(widget.size(), rect.size());
// move() while shown
- foreach (QRect r, rects) {
-#ifdef Q_WS_X11
- if ((widget.width() == 0 || widget.height() == 0) && r.width() != 0 && r.height() != 0) {
+ foreach (const QRect &r, rects) {
+ if (m_platform == QStringLiteral("xcb")
+ && ((widget.width() == 0 || widget.height() == 0) && r.width() != 0 && r.height() != 0)) {
QEXPECT_FAIL("130,100 0x200, flags 0",
"First resize after show of zero-sized gets wrong win_gravity.",
Continue);
"First resize after show of zero-sized gets wrong win_gravity.",
Continue);
}
-#endif
+
widget.move(r.topLeft());
widget.resize(r.size());
QApplication::processEvents();
widget.move(r.topLeft());
widget.resize(r.size());
QApplication::processEvents();
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_MAC)
if (r.width() == 0 && r.height() > 0) {
widget.move(r.topLeft());
widget.resize(r.size());
widget.move(r.topLeft());
widget.resize(r.size());
QApplication::processEvents();
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_MAC)
if (r.width() == 0 && r.height() > 0) {
widget.move(r.topLeft());
widget.resize(r.size());
QTRY_COMPARE(widget.size(), rect.size());
}
}
-#endif
class ColorWidget : public QWidget
{
#define VERIFY_COLOR(region, color) { \
const QRegion r = QRegion(region); \
+ QScreen *screen = qApp->primaryScreen(); \
+ const WId desktopWinId = QDesktopWidget().winId(); \
for (int i = 0; i < r.rects().size(); ++i) { \
const QRect rect = r.rects().at(i); \
for (int t = 0; t < 5; t++) { \
- const QPixmap pixmap = QPixmap::grabWindow(QDesktopWidget().winId(), \
+ const QPixmap pixmap = screen->grabWindow(desktopWinId, \
rect.left(), rect.top(), \
rect.width(), rect.height()); \
QCOMPARE(pixmap.size(), rect.size()); \
} \
}
+void tst_QWidget::popupEnterLeave()
+{
+ QWidget parent;
+ parent.setWindowFlags(Qt::FramelessWindowHint);
+ parent.setGeometry(10, 10, 200, 100);
+
+ ColorWidget alien(&parent, Qt::black);
+ alien.setGeometry(0, 0, 10, 10);
+ alien.show();
+
+ parent.show();
+
+ QTest::qWaitForWindowShown(parent.windowHandle());
+
+ QWindowSystemInterface::handleMouseEvent(parent.windowHandle(), QPointF(5, 5), QPointF(), Qt::LeftButton, Qt::NoModifier);
+ QTest::qWait(100);
+ QWindowSystemInterface::handleMouseEvent(parent.windowHandle(), QPointF(5, 5), QPointF(), Qt::NoButton, Qt::NoModifier);
+ QTest::qWait(100);
+
+ QStringList wordList;
+ wordList << "alpha" << "omega" << "omicron" << "zeta";
+
+ QLineEdit popup(&parent);
+
+ QCompleter completer(wordList);
+ completer.setCaseSensitivity(Qt::CaseInsensitive);
+ popup.setCompleter(&completer);
+ popup.setWindowFlags(Qt::Popup);
+ popup.setGeometry(20, 20, 80, 20);
+
+ popup.show();
+
+ QTest::qWaitForWindowShown(popup.windowHandle());
+
+ QTest::qWait(100);
+
+ QWindowSystemInterface::handleMouseEvent(popup.windowHandle(), QPointF(-5, -5), QPointF(), Qt::LeftButton, Qt::NoModifier);
+ QTest::qWait(100);
+ QWindowSystemInterface::handleMouseEvent(popup.windowHandle(), QPointF(-5, -5), QPointF(), Qt::NoButton, Qt::NoModifier);
+ QTest::qWait(100);
+
+ QTest::qWait(1000);
+ QVERIFY(!popup.underMouse());
+}
+
void tst_QWidget::moveChild_data()
{
QTest::addColumn<QPoint>("offset");
QTRY_COMPARE(pos, child.pos());
QCOMPARE(parent.r, QRegion(oldGeometry) - child.geometry());
-#if !defined(Q_WS_MAC)
+#if !defined(Q_OS_MAC)
// should be scrolled in backingstore
QCOMPARE(child.r, QRegion());
#endif
qApp->processEvents();
}
-#ifdef Q_WS_WIN
-void tst_QWidget::getDC()
-{
- QWidget widget;
- widget.setGeometry(0, 0, 2, 4);
-
- HDC dc = widget.getDC();
- QVERIFY(dc != 0);
-
- widget.releaseDC(dc);
-}
-#endif
-
class TopLevelFocusCheck: public QWidget
{
Q_OBJECT
QApplication::processEvents();
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&w2));
QTest::mouseClick(&w2, Qt::LeftButton);
-#ifdef Q_WS_QWS
- QEXPECT_FAIL("", "embedded toplevels take focus anyway", Continue);
-#endif
QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0);
QTest::mouseDClick(&w2, Qt::LeftButton);
QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0);
}
+class FocusWidget: public QWidget
+{
+protected:
+ virtual bool event(QEvent *ev)
+ {
+ if (ev->type() == QEvent::FocusAboutToChange)
+ widgetDuringFocusAboutToChange = qApp->focusWidget();
+ return QWidget::event(ev);
+ }
+ virtual void focusOutEvent(QFocusEvent *)
+ {
+ widgetDuringFocusOut = qApp->focusWidget();
+ }
+
+public:
+ FocusWidget(QWidget *parent) : QWidget(parent), widgetDuringFocusAboutToChange(0), widgetDuringFocusOut(0) {}
+
+ QWidget *widgetDuringFocusAboutToChange;
+ QWidget *widgetDuringFocusOut;
+};
+
void tst_QWidget::setFocus()
{
{
// window and children show, but window *is* active, children get focus
QWidget window;
- QWidget child1(&window);
+ FocusWidget child1(&window);
child1.setFocusPolicy(Qt::StrongFocus);
QWidget child2(&window);
child2.setFocusPolicy(Qt::StrongFocus);
window.show();
-#ifdef Q_WS_X11
- QApplication::setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
-#else
window.activateWindow();
- QApplication::processEvents();
-#endif
+ QTest::qWaitForWindowShown(&window);
+ QTRY_VERIFY(qGuiApp->focusWindow());
child1.setFocus();
QTRY_VERIFY(child1.hasFocus());
QVERIFY(child2.hasFocus());
QCOMPARE(window.focusWidget(), &child2);
QCOMPARE(QApplication::focusWidget(), &child2);
+
+ // focus changed in between the events
+ QCOMPARE(child1.widgetDuringFocusAboutToChange, &child1);
+ QCOMPARE(child1.widgetDuringFocusOut, &child2);
}
{
QWidget window;
window.show();
-#ifdef Q_WS_X11
- QApplication::setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
-#else
window.activateWindow();
-#endif
+ QTest::qWaitForWindowShown(&window);
+ QTRY_VERIFY(qGuiApp->focusWindow());
QWidget child1(&window);
child1.setFocusPolicy(Qt::StrongFocus);
QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(0));
child1.show();
-#ifdef Q_WS_X11
- QApplication::setActiveWindow(&child1);
- child1.activateWindow();
-#endif
QApplication::processEvents();
QTRY_VERIFY(child1.hasFocus());
QCOMPARE(window.focusWidget(), &child1);
QWidget window;
window.show();
-#ifdef Q_WS_X11
- QApplication::setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
-#else
window.activateWindow();
-#endif
+ QTest::qWaitForWindowShown(&window);
+ QTRY_VERIFY(qGuiApp->focusWindow());
QWidget child1(&window);
child1.setFocusPolicy(Qt::StrongFocus);
qApp->setWindowIcon(QIcon());
}
-#ifdef Q_WS_X11
void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint()
{
+ if (m_platform != QStringLiteral("xcb"))
+ QSKIP("This test is for X11 only.");
// Same size as in QWidget::create_sys().
const QSize desktopSize = QApplication::desktop()->size();
const QSize originalSize(desktopSize.width() / 2, desktopSize.height() * 4 / 10);
QCOMPARE(widget.size(), newMaximumSize);
widget.show();
- qt_x11_wait_for_window_manager(&widget);
+ QTest::qWaitForWindowShown(widget.windowHandle());
QCOMPARE(widget.size(), newMaximumSize);
}
QCOMPARE(widget.size(), newMinimumSize);
widget.show();
- qt_x11_wait_for_window_manager(&widget);
+ QTest::qWaitForWindowShown(widget.windowHandle());
QCOMPARE(widget.size(), newMinimumSize);
}
}
}
}
- bool x11Event(XEvent *event)
+ bool nativeEvent(const QByteArray &eventType, void *message, long *)
{
- if (state == 1 && event->type == MapNotify)
- gotExpectedMapNotify = true;
+ enum { XCB_MAP_NOTIFY = 19 };
+
+ if (state == 1 && eventType == QByteArrayLiteral("xcb_generic_event_t")) {
+ // XCB events have a uint8 response_type member at the beginning.
+ const unsigned char responseType = *(const unsigned char *)(message);
+ if ((responseType & ~0x80) == XCB_MAP_NOTIFY)
+ gotExpectedMapNotify = true;
+ }
return false;
}
void done();
};
-void tst_QWidget::showHideShow()
+void tst_QWidget::showHideShowX11()
{
+ if (m_platform != QStringLiteral("xcb"))
+ QSKIP("This test is for X11 only.");
+
ShowHideShowWidget w;
w.show();
w.hide();
void tst_QWidget::clean_qt_x11_enforce_cursor()
{
+ if (m_platform != QStringLiteral("xcb"))
+ QSKIP("This test is for X11 only.");
+
{
QWidget window;
QWidget *w = new QWidget(&window);
// If the test didn't crash, then it passed.
}
-#endif
class EventRecorder : public QObject
{
EventList events;
};
-void tst_QWidget::compatibilityChildInsertedEvents()
+void tst_QWidget::childEvents()
{
EventRecorder::EventList expected;
- bool accessibilityEnabled = false;
// Move away the cursor; otherwise it might result in an enter event if it's
// inside the widget when the widget is shown.
<< qMakePair(&widget, QEvent::Resize)
<< qMakePair(&widget, QEvent::Show);
- if (accessibilityEnabled)
- expected << qMakePair(&widget, QEvent::AccessibilityPrepare);
expected << qMakePair(&widget, QEvent::ShowToParent);
QCOMPARE(spy.eventList(), expected);
spy.clear();
<< qMakePair(&widget, QEvent::Resize)
<< qMakePair(&widget, QEvent::Show);
- if (accessibilityEnabled)
- expected << qMakePair(&widget, QEvent::AccessibilityPrepare);
expected << qMakePair(&widget, QEvent::ShowToParent);
QCOMPARE(spy.eventList(), expected);
spy.clear();
<< qMakePair(&widget, QEvent::Resize)
<< qMakePair(&widget, QEvent::Show);
- if (accessibilityEnabled)
- expected << qMakePair(&widget, QEvent::AccessibilityPrepare);
expected << qMakePair(&widget, QEvent::ShowToParent);
QCOMPARE(spy.eventList(), expected);
spy.clear();
qApp->sendPostedEvents();
QTest::qWait(250);
- QImage sourceImage = QPixmap::grabWidget(&source).toImage();
+ const QImage sourceImage = source.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage();
qApp->processEvents();
- QImage targetImage = QPixmap::grabWidget(&target).toImage();
+ QImage targetImage = target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage();
qApp->processEvents();
QCOMPARE(sourceImage, targetImage);
qApp->processEvents();
qApp->sendPostedEvents();
- targetImage = QPixmap::grabWidget(&target).toImage();
+ targetImage = target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage();
QVERIFY(sourceImage != targetImage);
QCOMPARE(targetImage.pixel(target.width() / 2, 29), QColor(Qt::red).rgb());
child.show();
qApp->processEvents();
- QCOMPARE(QPixmap::grabWidget(&child), QPixmap::grabWidget(&window));
+ const QPixmap childPixmap = child.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
+ const QPixmap windowPixmap = window.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
+ QCOMPARE(childPixmap, windowPixmap);
}
{ // Check that the target offset is correct.
// in testing the geometry so just workaround the palette issue for now.
static void workaroundPaletteIssue(QWidget *widget)
{
-#ifndef Q_WS_WIN
+#ifndef Q_OS_WIN
return;
#endif
if (!widget)
// Make sure QWidget::render does not trigger QWidget::repaint/update
// and asserts for Qt::WA_WState_Created.
- QPixmap pixmap = QPixmap::grabWidget(&mainWindow);
+ const QPixmap pixmap = mainWindow.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
+ Q_UNUSED(pixmap)
}
void tst_QWidget::render_task211796()
child.setAutoFillBackground(true);
QPixmap expected(child.size());
-#ifdef Q_WS_X11
- if (expected.depth() < 24)
+
+ if (m_platform == QStringLiteral("xcb") && expected.depth() < 24)
QSKIP("This test won't give correct results with dithered pixmaps");
-#endif
+
expected.fill(Qt::green);
QPainter painter(&expected);
painter.setOpacity(opacity);
// rrrrrrrrrr
// ...
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
for (int i = 0; i < image.height(); ++i) {
for (int j = 0; j < image.width(); ++j) {
if (i < 50 && j < i)
QCOMPARE(newSize, label3.sizeHint());
}
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
void tst_QWidget::moveWindowInShowEvent_data()
{
QTest::addColumn<QPoint>("initial");
// show it
widget.show();
- #ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&widget);
- #endif
+ QTest::qWaitForWindowShown(widget.windowHandle());
QTest::qWait(100);
// it should have moved
QCOMPARE(widget.pos(), position);
}
-#endif
void tst_QWidget::repaintWhenChildDeleted()
{
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
if (QSysInfo::WindowsVersion & QSysInfo::WV_VISTA) {
QTest::qWait(1000);
}
}
// This test doesn't make sense without support for showMinimized().
-#if !defined(Q_OS_WINCE) && !defined(Q_WS_QWS)
+#if !defined(Q_OS_WINCE)
void tst_QWidget::updateWhileMinimized()
{
UpdateWidget widget;
}
#endif
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
class PaintOnScreenWidget: public QWidget
{
public:
:QWidget(parent, f)
{
}
-#if defined(Q_WS_WIN)
+#if defined(Q_OS_WIN)
// This is the only way to enable PaintOnScreen on Windows.
QPaintEngine * paintEngine () const {return 0;}
#endif
void tst_QWidget::alienWidgets()
{
+ if (m_platform != QStringLiteral("xcb") && m_platform != QStringLiteral("windows"))
+ QSKIP("This test is only for X11/Windows.");
+
qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QWidget parent;
QWidget child(&parent);
QWidget greatGrandChild(&grandChild);
parent.show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&parent);
-#endif
+ QTest::qWaitForWindowShown(parent.windowHandle());
// Verify that the WA_WState_Created attribute is set
// and the top-level is the only native window.
widget.show();
QVERIFY(widget.testAttribute(Qt::WA_WState_Created));
QVERIFY(!widget.internalWinId());
-#ifdef Q_WS_X11
- widget.handle();
-#else
- widget.getDC();
-#endif
- QVERIFY(widget.internalWinId());
- }
-#ifdef Q_WS_X11
-#ifndef QT_NO_XRENDER
- { // Enforce a native window when calling QWidget::x11PictureHandle().
- QWidget widget(&parent);
- widget.show();
- QVERIFY(widget.testAttribute(Qt::WA_WState_Created));
- QVERIFY(!widget.internalWinId());
- widget.x11PictureHandle();
+ widget.winId();
QVERIFY(widget.internalWinId());
}
-#endif
- { // Make sure we don't create native windows when setting Qt::WA_X11NetWmWindowType attributes
- // on alien widgets (see task 194231).
+ if (m_platform == QStringLiteral("xcb")) {
+ // Make sure we don't create native windows when setting Qt::WA_X11NetWmWindowType attributes
+ // on alien widgets (see task 194231).
QWidget dummy;
QVERIFY(dummy.winId());
QWidget widget(&dummy);
widget.setAttribute(Qt::WA_X11NetWmWindowTypeToolBar);
QVERIFY(!widget.internalWinId());
}
-#endif
-
{ // Make sure we create native ancestors when setting Qt::WA_PaintOnScreen before show().
QWidget topLevel;
QVERIFY(toolBar->testAttribute(Qt::WA_NativeWindow));
}
}
-#endif // Q_WS_WIN / Q_WS_X11
class ASWidget : public QWidget
{
void tst_QWidget::sendUpdateRequestImmediately()
{
-#ifdef Q_WS_MAC
- if (!QApplicationPrivate::graphicsSystem())
- QSKIP("We only send update requests on the Mac when passing -graphicssystem");
-#endif
-
UpdateWidget updateWidget;
updateWidget.show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&updateWidget);
-#endif
+
+ QTest::qWaitForWindowShown(updateWidget.windowHandle());
qApp->processEvents();
-#ifdef Q_WS_QWS
- QApplication::sendPostedEvents(); //glib workaround
-#endif
updateWidget.reset();
QCOMPARE(updateWidget.numUpdateRequestEvents, 0);
QCOMPARE(updateWidget.numUpdateRequestEvents, 1);
}
-// 4DWM issues on IRIX makes this test fail.
-#ifndef Q_OS_IRIX
void tst_QWidget::doubleRepaint()
{
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_MAC)
if (!macHasAccessToWindowsServer())
QSKIP("Not having window server access causes the wrong number of repaints to be issues");
#endif
QTest::qWait(10);
QCOMPARE(widget.numPaintEvents, 0);
}
-#endif
-#ifndef Q_WS_MAC
-// This test only makes sense on the Mac when passing -graphicssystem.
void tst_QWidget::resizeInPaintEvent()
{
QWidget window;
greatGrandChild.setAutoFillBackground(true); // Opaque child widget.
widget.show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&widget);
-#endif
+ QTest::qWaitForWindowShown(widget.windowHandle());
QTest::qWait(100);
// Child, grandChild and greatGrandChild are outside the ancestor clip.
greatGrandChild.setAutoFillBackground(false);
QCOMPARE(qt_widget_private(&grandChild)->getOpaqueChildren(), QRegion());
}
-#endif
class MaskSetWidget : public QWidget
QTRY_COMPARE(testWidget.geometry(), expectedGeometry);
}
-
-#if defined(Q_WS_WIN) || defined(Q_WS_X11)
void tst_QWidget::immediateRepaintAfterShow()
{
+ if (m_platform != QStringLiteral("xcb") && m_platform != QStringLiteral("windows"))
+ QSKIP("We don't support immediate repaint right after show on other platforms.");
+
UpdateWidget widget;
widget.show();
qApp->processEvents();
void tst_QWidget::immediateRepaintAfterInvalidateBuffer()
{
+ if (m_platform != QStringLiteral("xcb") && m_platform != QStringLiteral("windows"))
+ QSKIP("We don't support immediate repaint right after show on other platforms.");
+
QWidget *widget = new UpdateWidget;
widget->show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(widget);
-#endif
+ QTest::qWaitForWindowShown(widget->windowHandle());
QTest::qWait(200);
static_cast<UpdateWidget *>(widget)->numPaintEvents = 0;
delete widget;
}
-#endif
void tst_QWidget::effectiveWinId()
{
child.move(10, 10); // Don't crash.
}
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
class GDIWidget : public QDialog
{
+ Q_OBJECT
public:
GDIWidget() { setAttribute(Qt::WA_PaintOnScreen); }
QPaintEngine *paintEngine() const { return 0; }
void paintEvent(QPaintEvent *) {
- HDC hdc = getDC();
+ QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface();
+ const HDC hdc = (HDC)ni->nativeResourceForWindow(QByteArrayLiteral("getDC"), windowHandle());
+ if (!hdc) {
+ qWarning("%s: Unable to obtain native DC.", Q_FUNC_INFO);
+ QTimer::singleShot(0, this, SLOT(reject()));
+ return;
+ }
SelectObject(hdc, CreateSolidBrush(RGB(255, 0, 0)));
Rectangle(hdc, 0, 0, 10, 10);
- releaseDC(hdc);
-
- QImage im = QPixmap::grabWindow(winId(), 0, 0, width(), height()).toImage();
- color = im.pixel(1, 1);
+ ni->nativeResourceForWindow(QByteArrayLiteral("releaseDC"), windowHandle());
- accept();
+ QTimer::singleShot(0, this, SLOT(slotTimer()));
}
QSize sizeHint() const {
return QSize(400, 300);
}
+private slots:
+ void slotTimer() {
+ QScreen *screen = windowHandle()->screen();
+ const QImage im = screen->grabWindow(internalWinId(), 0, 0, -1, -1).toImage();
+ color = im.pixel(1, 1);
+ accept();
+ }
+
+public:
QColor color;
};
w2.setAttribute(Qt::WA_PaintOnScreen);
QVERIFY(w2.testAttribute(Qt::WA_PaintOnScreen));
}
-#endif
+#endif // Q_OS_WIN
void tst_QWidget::reparentStaticWidget()
{
//do not crash
}
-#ifdef Q_WS_QWS
-void tst_QWidget::updateOutsideSurfaceClip()
-{
- UpdateWidget widget;
- widget.setWindowFlags(Qt::FramelessWindowHint);
- widget.resize(100, 100);
- widget.raise();
- widget.show();
- QTest::qWait(200);
- widget.reset();
-
- // Move widget partially outside buffer and change the surface clip.
- widget.move(-50, 0);
- QTest::qWait(100);
-
- // Update region is outside the surface clip and should not trigger a repaint.
- widget.update(0, 0, 20, 20);
- QTest::qWait(100);
- QCOMPARE(widget.numPaintEvents, 0);
-
- // Now, move the widget back so that the update region is inside the clip
- // and make sure we get a repaint of the dirty area.
- widget.move(0, 0);
- QTest::qWait(100);
- QCOMPARE(widget.numPaintEvents, 1);
- QCOMPARE(widget.paintedRegion, QRegion(0, 0, 20, 20));
-}
-#endif
class ColorRedWidget : public QWidget
{
public:
ColorRedWidget label;
label.setFixedSize(16,16);
label.setAttribute(Qt::WA_TranslucentBackground);
- label.move(qApp->desktop()->availableGeometry().topLeft());
+ const QPoint labelPos = qApp->desktop()->availableGeometry().topLeft();
+ label.move(labelPos);
label.show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&label);
-#endif
+ QTest::qWaitForWindowShown(label.windowHandle());
QTest::qWait(200);
QPixmap widgetSnapshot;
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
QWidget *desktopWidget = QApplication::desktop()->screen(0);
if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA)
- widgetSnapshot = QPixmap::grabWindow(desktopWidget->winId(), 0,0, label.width(), label.height());
+ widgetSnapshot = qApp->primaryScreen()->grabWindow(desktopWidget->winId(), labelPos.x(), labelPos.y(), label.width(), label.height());
else
#endif
- widgetSnapshot = QPixmap::grabWindow(label.winId());
+ widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size()));
QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32);
QImage expected = pm.toImage().convertToFormat(QImage::Format_RGB32);
QCOMPARE(actual.size(),expected.size());
const QRegion topLevelMask(0, 0, 100, 100, QRegion::Ellipse);
topLevel.setMask(topLevelMask);
QCOMPARE(topLevel.mask(), topLevelMask);
-#if defined(Q_WS_WIN) || defined(Q_WS_X11) // We don't control what's happening on other platforms.
- // and ensure that the top-level doesn't get any update.
- QCOMPARE(topLevel.numPaintEvents, 0);
-#endif
+ // Ensure that the top-level doesn't get any update.
+ // We don't control what's happening on platforms other than X11, Windows
+ if (m_platform == QStringLiteral("xcb") || m_platform == QStringLiteral("windows"))
+ QCOMPARE(topLevel.numPaintEvents, 0);
topLevel.reset();
QTest::qWait(10);
QRegion outsideOldMask(topLevel.rect());
outsideOldMask -= topLevelMask;
-#if defined(Q_WS_WIN) || defined(Q_WS_X11) // We don't control what's happening on other platforms.
- // and ensure that the top-level gets an update for the area outside the old mask.
- QTRY_VERIFY(topLevel.numPaintEvents > 0);
- QTRY_COMPARE(topLevel.paintedRegion, outsideOldMask);
-#endif
+ // Ensure that the top-level gets an update for the area outside the old mask.
+ // We don't control what's happening on platforms other than X11, Windows
+ if (m_platform == QStringLiteral("xcb") || m_platform == QStringLiteral("windows")) {
+ QTRY_VERIFY(topLevel.numPaintEvents > 0);
+ QTRY_COMPARE(topLevel.paintedRegion, outsideOldMask);
+ }
UpdateWidget child(&topLevel);
child.setAutoFillBackground(true); // NB! Opaque child.
QTRY_COMPARE(child.mask(), childMask);
QTest::qWait(50);
// and ensure that the child widget doesn't get any update.
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
// Mac always issues a full update when calling setMask, and we cannot force it to not do so.
if (child.internalWinId())
QCOMPARE(child.numPaintEvents, 1);
// and ensure that that the child widget gets an update for the area outside the old mask.
QTRY_COMPARE(child.numPaintEvents, 1);
outsideOldMask = child.rect();
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
// Mac always issues a full update when calling setMask, and we cannot force it to not do so.
if (!child.internalWinId())
#endif
// Mask child widget with a mask that is bigger than the rect
child.setMask(QRegion(0, 0, 1000, 1000));
QTest::qWait(100);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
// Mac always issues a full update when calling setMask, and we cannot force it to not do so.
if (child.internalWinId())
QTRY_COMPARE(child.numPaintEvents, 1);
// ...and the same applies when clearing the mask.
child.clearMask();
QTest::qWait(100);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
// Mac always issues a full update when calling setMask, and we cannot force it to not do so.
if (child.internalWinId())
QTRY_VERIFY(child.numPaintEvents > 0);
QTimer::singleShot(100, &resizeChild, SLOT(shrinkMask()));
QTest::qWait(200);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
// Mac always issues a full update when calling setMask, and we cannot force it to not do so.
if (child.internalWinId())
QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask());
const QRegion oldMask = resizeChild.mask();
QTimer::singleShot(0, &resizeChild, SLOT(enlargeMask()));
QTest::qWait(100);
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
// Mac always issues a full update when calling setMask, and we cannot force it to not do so.
if (child.internalWinId())
QTRY_COMPARE(resizeChild.paintedRegion, resizeChild.mask());
window.show();
window.raise();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&window);
-#endif
+
+ QTest::qWaitForWindowShown(window.windowHandle());
QTest::qWait(300);
#define RESET_EVENT_COUNTS \
SELChild child(&parent);
child.resize(200, 200);
parent.show();
- #ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&parent);
- #endif
+ QTest::qWaitForWindowShown(parent.windowHandle());
QTest::qWait(150);
QCursor::setPos(child.mapToGlobal(QPoint(100, 100)));
}
}
-#ifdef Q_WS_X11
-void tst_QWidget::paintOutsidePaintEvent()
-{
- QWidget widget;
- widget.resize(200, 200);
-
- QWidget child1(&widget);
- child1.resize(100, 100);
- child1.setPalette(Qt::red);
- child1.setAutoFillBackground(true);
-
- QWidget child2(&widget);
- child2.setGeometry(50, 50, 100, 100);
- child2.setPalette(Qt::blue);
- child2.setAutoFillBackground(true);
-
- widget.show();
- QTest::qWaitForWindowShown(&widget);
- QTest::qWait(60);
-
- const QPixmap before = QPixmap::grabWindow(widget.winId());
-
- // Child 1 should be clipped by child 2, so nothing should change.
- child1.setAttribute(Qt::WA_PaintOutsidePaintEvent);
- QPainter painter(&child1);
- painter.fillRect(child1.rect(), Qt::red);
- painter.end();
- XSync(QX11Info::display(), false); // Flush output buffer.
- QTest::qWait(60);
-
- const QPixmap after = QPixmap::grabWindow(widget.winId());
-
- QCOMPARE(before, after);
-}
-#endif
-
class MyEvilObject : public QObject
{
Q_OBJECT
child->setPalette(Qt::red);
widget.show();
-#ifdef Q_WS_X11
- qt_x11_wait_for_window_manager(&widget);
-#endif
+ QTest::qWaitForWindowShown(widget.windowHandle());
QTest::qWait(200);
// Please do not crash.
w.update();
QApplication::processEvents();
-#ifdef Q_WS_QWS
- QApplication::processEvents();
-#endif
+
QCOMPARE(w.numPaintEvents, 1);
// Check one more time, because the second time around does more caching.
QApplication::processEvents();
QCOMPARE(w.numPaintEvents, 2);
}
-#endif
+#endif // QT_BUILD_INTERNAL
// Helper function
QWidgetBackingStore* backingStore(QWidget &widget)
QPixmap correct(main.size());
correct.fill(Qt::green);
+ const QPixmap mainPixmap = main.grab(QRect(QPoint(0, 0), QSize(-1, -1)));
- QTRY_COMPARE(QPixmap::grabWindow(main.winId()).toImage().convertToFormat(QImage::Format_RGB32),
+ QTRY_COMPARE(mainPixmap.toImage().convertToFormat(QImage::Format_RGB32),
correct.toImage().convertToFormat(QImage::Format_RGB32));
QApplication::restoreOverrideCursor();
}
void tst_QWidget::inputFocus_task257832()
{
QLineEdit *widget = new QLineEdit;
- QInputContext *context = widget->inputContext();
- if (!context)
- QSKIP("No input context");
widget->setFocus();
widget->winId(); // make sure, widget has been created
- context->setFocusWidget(widget);
- QCOMPARE(context->focusWidget(), static_cast<QWidget*>(widget));
+ widget->show();
+ QTRY_VERIFY(widget->hasFocus());
+ QCOMPARE(qApp->inputMethod()->inputItem(), static_cast<QWidget*>(widget));
widget->setReadOnly(true);
- QVERIFY(!context->focusWidget());
+ QVERIFY(!qApp->inputMethod()->inputItem());
delete widget;
}
delete win;
}
-class InputContextTester : public QInputContext
-{
- Q_OBJECT
-public:
- QString identifierName() { return QString(); }
- bool isComposing() const { return false; }
- QString language() { return QString(); }
- void reset() { ++resets; }
- int resets;
-};
-
void tst_QWidget::focusProxyAndInputMethods()
{
- InputContextTester *inputContext = new InputContextTester;
QWidget *toplevel = new QWidget(0, Qt::X11BypassWindowManagerHint);
toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
- qApp->setInputContext(inputContext); // ownership is transferred
QWidget *child = new QWidget(toplevel);
child->setFocusProxy(toplevel);
// and that the input method gets the focus proxy passed
// as the focus widget instead of the child widget.
// otherwise input method queries go to the wrong widget
+ QCOMPARE(qApp->inputPanel()->inputItem(), toplevel);
- QCOMPARE(inputContext->focusWidget(), toplevel);
+ toplevel->setAttribute(Qt::WA_InputMethodEnabled, false);
+ QVERIFY(!qApp->inputPanel()->inputItem());
- child->setAttribute(Qt::WA_InputMethodEnabled, false);
- QVERIFY(!inputContext->focusWidget());
-
- child->setAttribute(Qt::WA_InputMethodEnabled, true);
- QCOMPARE(inputContext->focusWidget(), toplevel);
-
- child->setEnabled(false);
- QVERIFY(!inputContext->focusWidget());
-
- child->setEnabled(true);
- QCOMPARE(inputContext->focusWidget(), toplevel);
+ toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
+ QCOMPARE(qApp->inputPanel()->inputItem(), toplevel);
delete toplevel;
}
void tst_QWidget::movedAndResizedAttributes()
{
-#if defined (Q_OS_MAC) || defined(Q_WS_QWS)
+#if defined (Q_OS_MAC)
QEXPECT_FAIL("", "FixMe, QTBUG-8941 and QTBUG-8977", Abort);
QVERIFY(false);
#else
w.showNormal();
w.move(10,10);
QVERIFY(w.testAttribute(Qt::WA_Moved));
-#if defined(Q_OS_WIN)
- QEXPECT_FAIL("", "FixMe, QTBUG-8911", Abort);
-#endif
QVERIFY(!w.testAttribute(Qt::WA_Resized));
w.resize(100, 100);
QCOMPARE(parent.childAt(120, 120), grandChild);
}
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
void tst_QWidget::childAt_unifiedToolBar()
{
QLabel *label = new QLabel(QLatin1String("foo"));
QTest::qWait(1000);
}
+static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
+{
+ QImage expectedImage = expected.toImage().convertToFormat(QImage::Format_RGB32);
+ QImage actualImage = actual.toImage().convertToFormat(QImage::Format_RGB32);
+
+ if (expectedImage.size() != actualImage.size()) {
+ qWarning("Image size comparison failed: expected: %dx%d, got %dx%d",
+ expectedImage.size().width(), expectedImage.size().height(),
+ actualImage.size().width(), actualImage.size().height());
+ return false;
+ }
+
+ const int size = actual.width() * actual.height();
+ const int threshold = QPixmap::defaultDepth() == 16 ? 10 : 2;
+
+ QRgb *a = (QRgb *)actualImage.bits();
+ QRgb *e = (QRgb *)expectedImage.bits();
+ for (int i = 0; i < size; ++i) {
+ const QColor ca(a[i]);
+ const QColor ce(e[i]);
+ if (qAbs(ca.red() - ce.red()) > threshold
+ || qAbs(ca.green() - ce.green()) > threshold
+ || qAbs(ca.blue() - ce.blue()) > threshold) {
+ qWarning("Color mismatch at pixel #%d: Expected: %d,%d,%d, got %d,%d,%d",
+ i, ce.red(), ce.green(), ce.blue(), ca.red(), ca.green(), ca.blue());
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void tst_QWidget::grab()
+{
+ for (int opaque = 0; opaque < 2; ++opaque) {
+ QWidget widget;
+ QImage image(128, 128, opaque ? QImage::Format_RGB32 : QImage::Format_ARGB32_Premultiplied);
+ for (int row = 0; row < image.height(); ++row) {
+ QRgb *line = reinterpret_cast<QRgb *>(image.scanLine(row));
+ for (int col = 0; col < image.width(); ++col)
+ line[col] = qRgba(rand() & 255, row, col, opaque ? 255 : 127);
+ }
+
+ QPalette pal = widget.palette();
+ pal.setBrush(QPalette::Window, QBrush(image));
+ widget.setPalette(pal);
+ widget.resize(128, 128);
+
+ QPixmap expected(64, 64);
+ if (!opaque)
+ expected.fill(Qt::transparent);
+
+ QPainter p(&expected);
+ p.translate(-64, -64);
+ p.drawTiledPixmap(0, 0, 128, 128, pal.brush(QPalette::Window).texture(), 0, 0);
+ p.end();
+
+ QPixmap actual = widget.grab(QRect(64, 64, 64, 64));
+ QVERIFY(lenientCompare(actual, expected));
+
+ actual = widget.grab(QRect(64, 64, -1, -1));
+ QVERIFY(lenientCompare(actual, expected));
+
+ // Make sure a widget that is not yet shown is grabbed correctly.
+ QTreeWidget widget2;
+ actual = widget2.grab(QRect());
+ widget2.show();
+ expected = widget2.grab(QRect());
+
+ QVERIFY(lenientCompare(actual, expected));
+ }
+}
+
QTEST_MAIN(tst_QWidget)
#include "tst_qwidget.moc"