QWidget child1(&obj1);
// QStyle * QWidget::style()
// void QWidget::setStyle(QStyle *)
- QWindowsStyle *var1 = new QWindowsStyle;
- obj1.setStyle(var1);
- QCOMPARE(static_cast<QStyle *>(var1), obj1.style());
+ QScopedPointer<QWindowsStyle> var1(new QWindowsStyle);
+ obj1.setStyle(var1.data());
+ QCOMPARE(static_cast<QStyle *>(var1.data()), obj1.style());
obj1.setStyle((QStyle *)0);
- QVERIFY(var1 != obj1.style());
+ QVERIFY(var1.data() != obj1.style());
QVERIFY(0 != obj1.style()); // style can never be 0 for a widget
// int QWidget::minimumWidth()
// QWidget * QWidget::focusProxy()
// void QWidget::setFocusProxy(QWidget *)
- QWidget *var9 = new QWidget();
- obj1.setFocusProxy(var9);
- QCOMPARE(var9, obj1.focusProxy());
- obj1.setFocusProxy((QWidget *)0);
- QCOMPARE((QWidget *)0, obj1.focusProxy());
- delete var9;
+ {
+ QScopedPointer<QWidget> var9(new QWidget());
+ obj1.setFocusProxy(var9.data());
+ QCOMPARE(var9.data(), obj1.focusProxy());
+ obj1.setFocusProxy((QWidget *)0);
+ QCOMPARE((QWidget *)0, obj1.focusProxy());
+ }
// const QRect & QWidget::geometry()
// void QWidget::setGeometry(const QRect &)
obj1.setAutoFillBackground(true);
QCOMPARE(true, obj1.autoFillBackground());
- delete var1;
+ var1.reset();
#if defined (Q_OS_WIN) && !defined(Q_OS_WINCE)
obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
const HWND handle = reinterpret_cast<HWND>(obj1.winId()); // explicitly create window handle
class BezierViewer : public QWidget {
public:
- BezierViewer( QWidget* parent=0, const char* name=0 );
+ explicit BezierViewer(QWidget* parent = 0);
void paintEvent( QPaintEvent* );
void setPoints( const QPolygonF& poly );
private:
qApp->setAutoMaximizeThreshold(-1);
#endif
// Create the test class
- testWidget = new BezierViewer( 0, "testObject");
+ testWidget = new BezierViewer;
testWidget->resize(200,200);
testWidget->show();
- QTest::qWaitForWindowShown(testWidget);
- QTest::qWait(50);
+ QVERIFY(QTest::qWaitForWindowExposed(testWidget));
}
void tst_QWidget::cleanupTestCase()
// Helper class...
-BezierViewer::BezierViewer( QWidget* parent, const char* name )
+BezierViewer::BezierViewer( QWidget* parent)
: QWidget( parent )
{
- setObjectName(name);
+ setObjectName(QLatin1String("TestWidget"));
+ setWindowTitle(objectName());
QPalette pal;
pal.setColor(backgroundRole(), Qt::white);
setPalette(pal);
// font.setPointSize(42);
// qApp->setFont(font, "QPropagationTestWidget");
- QWidget *root = new QWidget;
- QWidget *child0 = new QWidget(root);
+ QScopedPointer<QWidget> root(new QWidget);
+ root->setObjectName(QLatin1String("fontPropagation2"));
+ root->setWindowTitle(root->objectName());
+ root->resize(200, 200);
+
+ QWidget *child0 = new QWidget(root.data());
QWidget *child1 = new QWidget(child0);
QWidget *child2 = new QPropagationTestWidget(child1);
QWidget *child3 = new QWidget(child2);
// font.setColor(QPalette::Text, QColor(21, 22, 23));
// qApp->setPalette(palette, "QPropagationTestWidget");
- QWidget *root = new QWidget;
- QWidget *child0 = new QWidget(root);
+ QScopedPointer<QWidget> root(new QWidget);
+ root->setObjectName(QLatin1String("palettePropagation2"));
+ root->setWindowTitle(root->objectName());
+ root->resize(200, 200);
+ QWidget *child0 = new QWidget(root.data());
QWidget *child1 = new QWidget(child0);
QWidget *child2 = new QPropagationTestWidget(child1);
QWidget *child3 = new QWidget(child2);
QWidget *child4 = new QWidget(child3);
QWidget *child5 = new QWidget(child4);
root->show();
- QTest::qWait(100);
+ QVERIFY(QTest::qWaitForWindowExposed(root.data()));
// These colors are unlikely to be imposed on the default palette of
// QWidget ;-).
// create a toplevel and two overlapping siblings
QWidget window;
+ window.setObjectName(QStringLiteral("mapFromAndTo"));
+ window.setWindowTitle(window.objectName());
window.setWindowFlags(window.windowFlags() | Qt::X11BypassWindowManagerHint);
QWidget *subWindow1 = new QWidget(&window);
QWidget *subWindow2 = new QWidget(&window);
{
testWidget->hide(); // We do not want to get disturbed by other widgets
// focus should move to the next widget in the focus chain when we hide it.
- QWidget *parent = new QWidget();
- parent->setObjectName(QLatin1String("Parent"));
+ QScopedPointer<QWidget> parent(new QWidget());
+ parent->setObjectName(QLatin1String("focusChainOnHide"));
+ parent->resize(200, 200);
+ parent->setWindowTitle(parent->objectName());
parent->setFocusPolicy(Qt::StrongFocus);
- QWidget *child = new QWidget(parent);
+ QWidget *child = new QWidget(parent.data());
child->setObjectName(QLatin1String("child"));
child->setFocusPolicy(Qt::StrongFocus);
- QWidget::setTabOrder(child, parent);
+ QWidget::setTabOrder(child, parent.data());
parent->show();
qApp->setActiveWindow(parent->window());
qApp->processEvents();
QTRY_COMPARE(parent->hasFocus(), true);
- QCOMPARE(parent, qApp->focusWidget());
+ QCOMPARE(parent.data(), qApp->focusWidget());
- delete parent;
testWidget->show(); //don't disturb later tests
}
QTest::qWait(100);
Container container;
+ container.setObjectName("setTabOrder");
+ container.setWindowTitle(container.objectName());
Composite* comp[NUM_WIDGETS];
qApp->processEvents();
#endif
QWidget widget1;
- widget1.setWindowTitle("Widget1");
+ widget1.setObjectName("activation-Widget1");
+ widget1.setWindowTitle(widget1.objectName());
QWidget widget2;
- widget2.setWindowTitle("Widget2");
+ widget1.setObjectName("activation-Widget2");
+ widget1.setWindowTitle(widget2.objectName());
widget1.show();
widget2.show();
QCOMPARE(widget1.pos(), pos);
QCOMPARE(widget1.size(), size);
QTest::qWait(100);
- widget1.setWindowTitle("Widget1");
+ widget1.setObjectName(QStringLiteral("windowState-Widget1"));
+ widget1.setWindowTitle(widget1.objectName());
QCOMPARE(widget1.pos(), pos);
QCOMPARE(widget1.size(), size);
public:
ResizeWidget(QWidget *p = 0) : QWidget(p)
{
+ setObjectName(QLatin1String("ResizeWidget"));
+ setWindowTitle(objectName());
m_resizeEventCount = 0;
}
protected:
//here we test that minimizing a widget and restoring it doesn't change the focus inside of it
{
QWidget window;
+ window.resize(200, 200);
QWidget child1(&window), child2(&window);
child1.setFocusPolicy(Qt::StrongFocus);
child2.setFocusPolicy(Qt::StrongFocus);
window.show();
qApp->setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
child2.setFocus();
- QTest::qWait(50);
QTRY_COMPARE(window.focusWidget(), &child2);
QTRY_COMPARE(qApp->focusWidget(), &child2);
window.showMinimized();
- QTest::qWait(10);
QTRY_VERIFY(window.isMinimized());
QTRY_COMPARE(window.focusWidget(), &child2);
child->setFocusPolicy(Qt::StrongFocus);
window.show();
qApp->setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
child->setFocus();
- QTest::qWait(50);
QTRY_COMPARE(window.focusWidget(), child);
QTRY_COMPARE(qApp->focusWidget(), child);
child->setFocusPolicy(Qt::StrongFocus);
window.show();
qApp->setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
child->setFocus();
- QTest::qWait(50);
QTRY_COMPARE(window.focusWidget(), child);
QTRY_COMPARE(qApp->focusWidget(), child);
child->setFocusPolicy(Qt::StrongFocus);
window.show();
qApp->setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
child->setFocus();
- QTest::qWait(10);
QTRY_COMPARE(window.focusWidget(), child);
QTRY_COMPARE(qApp->focusWidget(), child);
child->setFocusPolicy(Qt::StrongFocus);
window.show();
qApp->setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
child->setFocus();
- QTest::qWait(10);
QTRY_COMPARE(window.focusWidget(), child);
QTRY_COMPARE(qApp->focusWidget(), child);
window.showNormal();
qApp->setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
- QTest::qWait(30);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
#ifdef Q_OS_MAC
if (!macHasAccessToWindowsServer())
QEXPECT_FAIL("", "When not having WindowServer access, we lose focus.", Continue);
parent.show();
childTLW.show();
- QTest::qWaitForWindowShown(&parent);
+ QVERIFY(QTest::qWaitForWindowExposed(&parent));
#ifdef Q_OS_WINCE
parent.move(50, 50);
void tst_QWidget::hideWhenFocusWidgetIsChild()
{
testWidget->activateWindow();
- QWidget *parentWidget = new QWidget(testWidget);
+ QScopedPointer<QWidget> parentWidget(new QWidget(testWidget));
parentWidget->setObjectName("parentWidget");
parentWidget->setGeometry(0, 0, 100, 100);
- QLineEdit *edit = new QLineEdit(parentWidget);
+ QLineEdit *edit = new QLineEdit(parentWidget.data());
edit->setObjectName("edit1");
- QLineEdit *edit3 = new QLineEdit(parentWidget);
+ QLineEdit *edit3 = new QLineEdit(parentWidget.data());
edit3->setObjectName("edit3");
edit3->move(0,50);
parentWidget->show();
actualFocusWidget.sprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className());
expectedFocusWidget.sprintf("%p %s %s", edit2, edit2->objectName().toLatin1().constData(), edit2->metaObject()->className());
QCOMPARE(actualFocusWidget, expectedFocusWidget);
-
- delete edit2;
- delete parentWidget;
}
void tst_QWidget::normalGeometry()
parent.setGeometry(100, 100, 200, 200);
parent.show();
- QTest::qWaitForWindowShown(&parent);
+ QVERIFY(QTest::qWaitForWindowExposed(&parent));
QApplication::processEvents();
QRect geom = parent.geometry();
{
public:
UpdateWidget(QWidget *parent = 0) : QWidget(parent) {
+ setObjectName(QLatin1String("UpdateWidget"));
+ setWindowTitle(objectName());
reset();
}
void tst_QWidget::raise()
{
QTest::qWait(10);
- QWidget *parent = new QWidget(0);
+ QScopedPointer<QWidget> parentPtr(new QWidget);
+ parentPtr->resize(200, 200);
+ parentPtr->setObjectName(QLatin1String("raise"));
+ parentPtr->setWindowTitle(parentPtr->objectName());
QList<UpdateWidget *> allChildren;
- UpdateWidget *child1 = new UpdateWidget(parent);
+ UpdateWidget *child1 = new UpdateWidget(parentPtr.data());
child1->setAutoFillBackground(true);
allChildren.append(child1);
- UpdateWidget *child2 = new UpdateWidget(parent);
+ UpdateWidget *child2 = new UpdateWidget(parentPtr.data());
child2->setAutoFillBackground(true);
allChildren.append(child2);
- UpdateWidget *child3 = new UpdateWidget(parent);
+ UpdateWidget *child3 = new UpdateWidget(parentPtr.data());
child3->setAutoFillBackground(true);
allChildren.append(child3);
- UpdateWidget *child4 = new UpdateWidget(parent);
+ UpdateWidget *child4 = new UpdateWidget(parentPtr.data());
child4->setAutoFillBackground(true);
allChildren.append(child4);
- parent->show();
- QTest::qWaitForWindowShown(parent);
+ parentPtr->show();
+ QVERIFY(QTest::qWaitForWindowExposed(parentPtr.data()));
QTest::qWait(10);
#ifdef Q_OS_MAC
QList<QObject *> list1;
list1 << child1 << child2 << child3 << child4;
- QVERIFY(parent->children() == list1);
+ QVERIFY(parentPtr->children() == list1);
QCOMPARE(allChildren.count(), list1.count());
foreach (UpdateWidget *child, allChildren) {
QList<QObject *> list2;
list2 << child1 << child3 << child4 << child2;
- QVERIFY(parent->children() == list2);
+ QVERIFY(parentPtr->children() == list2);
// Creates a widget on top of all the children and checks that raising one of
// the children underneath doesn't trigger a repaint on the covering widget.
QWidget topLevel;
+ QWidget *parent = parentPtr.take();
parent->setParent(&topLevel);
topLevel.show();
- QTest::qWaitForWindowShown(&topLevel);
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
QTest::qWait(50);
UpdateWidget *onTop = new UpdateWidget(&topLevel);
#ifndef QT_OS_MAC
void tst_QWidget::lower()
{
- QWidget *parent = new QWidget(0);
+ QScopedPointer<QWidget> parent(new QWidget);
+ parent->setObjectName(QLatin1String("lower"));
+ parent->setWindowTitle(parent->objectName());
+ parent->resize(200, 200);
QList<UpdateWidget *> allChildren;
- UpdateWidget *child1 = new UpdateWidget(parent);
+ UpdateWidget *child1 = new UpdateWidget(parent.data());
child1->setAutoFillBackground(true);
allChildren.append(child1);
- UpdateWidget *child2 = new UpdateWidget(parent);
+ UpdateWidget *child2 = new UpdateWidget(parent.data());
child2->setAutoFillBackground(true);
allChildren.append(child2);
- UpdateWidget *child3 = new UpdateWidget(parent);
+ UpdateWidget *child3 = new UpdateWidget(parent.data());
child3->setAutoFillBackground(true);
allChildren.append(child3);
- UpdateWidget *child4 = new UpdateWidget(parent);
+ UpdateWidget *child4 = new UpdateWidget(parent.data());
child4->setAutoFillBackground(true);
allChildren.append(child4);
parent->show();
- QTest::qWaitForWindowShown(parent);
- QTest::qWait(100);
+ QVERIFY(QTest::qWaitForWindowExposed(parent.data()));
QList<QObject *> list1;
list1 << child1 << child2 << child3 << child4;
QList<QObject *> list2;
list2 << child4 << child1 << child2 << child3;
QVERIFY(parent->children() == list2);
-
- delete parent;
}
#endif
#ifndef QT_OS_MAC
void tst_QWidget::stackUnder()
{
- QTest::qWait(10);
- QWidget *parent = new QWidget(0);
+ QScopedPointer<QWidget> parent(new QWidget);
+ parent->setObjectName(QLatin1String("stackUnder"));
+ parent->setWindowTitle(parent->objectName());
+ parent->resize(200, 200);
QList<UpdateWidget *> allChildren;
- UpdateWidget *child1 = new UpdateWidget(parent);
+ UpdateWidget *child1 = new UpdateWidget(parent.data());
child1->setAutoFillBackground(true);
allChildren.append(child1);
- UpdateWidget *child2 = new UpdateWidget(parent);
+ UpdateWidget *child2 = new UpdateWidget(parent.data());
child2->setAutoFillBackground(true);
allChildren.append(child2);
- UpdateWidget *child3 = new UpdateWidget(parent);
+ UpdateWidget *child3 = new UpdateWidget(parent.data());
child3->setAutoFillBackground(true);
allChildren.append(child3);
- UpdateWidget *child4 = new UpdateWidget(parent);
+ UpdateWidget *child4 = new UpdateWidget(parent.data());
child4->setAutoFillBackground(true);
allChildren.append(child4);
parent->show();
- QTest::qWaitForWindowShown(parent);
- QTest::qWait(10);
+ QVERIFY(QTest::qWaitForWindowExposed(parent.data()));
QList<QObject *> list1;
list1 << child1 << child2 << child3 << child4;
QVERIFY(parent->children() == list1);
QTRY_COMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents);
child->reset();
}
-
- delete parent;
}
#endif
public:
ContentsPropagationWidget(QWidget *parent = 0) : QWidget(parent)
{
+ setObjectName(QLatin1String("ContentsPropagationWidget"));
+ setWindowTitle(objectName());
QWidget *child = this;
for (int i=0; i<32; ++i) {
child = new QWidget(child);
widget.move(position);
widget.resize(size);
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QApplication::processEvents();
QTRY_COMPARE(widget.pos(), position);
QVERIFY(widget.restoreGeometry(savedGeometry));
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QApplication::processEvents();
QTRY_COMPARE(widget.pos(), position);
widget.move(position);
widget.resize(size);
widget.show();
- QTest::qWaitForWindowShown(&widget);
- QTest::qWait(500);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QTRY_COMPARE(widget.geometry().size(), size);
QRect geom;
QCOMPARE(widget.size(), expectedSize);
}
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QTest::qWait(100);
if (expectedWindowState == Qt::WindowNoState) {
{
Q_CHECK_PAINTEVENTS
- QWidget *w1 = new QWidget(0, Qt::X11BypassWindowManagerHint);
- w1->setGeometry(0,0,150,150);
- w1->setObjectName("w1");
-
- QWidget *w2 = new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint);
- w2->setGeometry(50,50,100,100);
- w2->setObjectName("w2");
+ QScopedPointer<QWidget> w1(new QWidget(0, Qt::X11BypassWindowManagerHint));
+ w1->setGeometry(0, 0, 160, 150);
+ w1->setObjectName(QLatin1String("w1"));
+ w1->setWindowTitle(w1->objectName());
+ QScopedPointer<QWidget> w2(new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint));
+ w2->setGeometry(50,50, 160, 100);
+ w2->setObjectName(QLatin1String("w2"));
+ w2->setWindowTitle(w2->objectName());
w1->show();
- QTest::qWaitForWindowShown(w1);
+ QVERIFY(QTest::qWaitForWindowExposed(w1.data()));
qApp->processEvents();
QWidget *wr;
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100)));
QCOMPARE(wr->objectName(), QString("w1"));
w2->show();
- QTest::qWaitForWindowShown(w2);
+ QVERIFY(QTest::qWaitForWindowExposed(w2.data()));
qApp->processEvents();
qApp->processEvents();
qApp->processEvents();
qApp->processEvents();
QTRY_VERIFY((wr = QApplication::widgetAt(100, 100)) && wr->objectName() == QString("w2"));
- QWidget *w3 = new QWidget(w2);
+ QWidget *w3 = new QWidget(w2.data());
w3->setGeometry(10,10,50,50);
w3->setObjectName("w3");
w3->show();
#endif
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 w2;
- delete w1;
+ QTRY_VERIFY(QApplication::widgetAt(100,100) == w1.data());
+ QTRY_VERIFY(QApplication::widgetAt(101,101) == w2.data());
}
void tst_QWidget::task110173()
QTest::keyClick( &w, Qt::Key_Tab );
w.show();
- QTest::qWaitForWindowShown(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QTest::qWait(200);
}
staticWidget.move(150, 150);
staticWidget.resize(150, 150);
parent.show();
- QTest::qWaitForWindowShown(&parent);
+ QVERIFY(QTest::qWaitForWindowExposed(&parent));
QTest::qWait(20);
QTRY_COMPARE(staticWidget.gotPaintEvent, true);
StaticWidget topLevel;
topLevel.gotPaintEvent = false;
topLevel.show();
- QTest::qWaitForWindowShown(&topLevel);
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
QTest::qWait(10);
QTRY_COMPARE(topLevel.gotPaintEvent, true);
void tst_QWidget::persistentWinId()
{
- QWidget *parent = new QWidget;
+ QScopedPointer<QWidget> parent(new QWidget);
QWidget *w1 = new QWidget;
QWidget *w2 = new QWidget;
QWidget *w3 = new QWidget;
- w1->setParent(parent);
+ w1->setParent(parent.data());
w2->setParent(w1);
w3->setParent(w2);
QCOMPARE(w2->winId(), winId2);
QCOMPARE(w3->winId(), winId3);
- w1->setParent(parent);
+ w1->setParent(parent.data());
if (m_platform == QStringLiteral("windows"))
QEXPECT_FAIL("", "QTBUG-26424", Continue);
QVERIFY(w1->winId() != winId1);
winId2 = w2->winId();
QCOMPARE(w3->winId(), winId3);
- w2->setParent(parent);
+ w2->setParent(parent.data());
if (m_platform == QStringLiteral("windows"))
QEXPECT_FAIL("", "QTBUG-26424", Continue);
QVERIFY(w2->winId() != winId2);
QEXPECT_FAIL("", "QTBUG-26424", Continue);
QVERIFY(w3->winId() != winId3);
winId3 = w3->winId();
-
- delete parent;
}
void tst_QWidget::showNativeChild()
{
QWidget topLevel;
- topLevel.setGeometry(0, 0, 100, 100);
+ topLevel.setGeometry(0, 0, 160, 160);
QWidget child(&topLevel);
child.winId();
topLevel.show();
- QTest::qWaitForWindowShown(&topLevel);
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
}
class ShowHideEventWidget : public QWidget
UpdateWidget w;
w.setGeometry(50, 50, 100, 100);
w.show();
- QTest::qWaitForWindowShown(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QApplication::processEvents();
QApplication::processEvents();
updateWidget.resize(500, 500);
updateWidget.reset();
updateWidget.show();
- QTest::qWaitForWindowShown(&updateWidget);
- QTest::qWait(50);
- qApp->processEvents();
- QTRY_VERIFY(updateWidget.numPaintEvents > 0);
+ qApp->setActiveWindow(&updateWidget);
+ QVERIFY(QTest::qWaitForWindowActive(&updateWidget));
+ QVERIFY(updateWidget.numPaintEvents > 0);
{
updateWidget.reset();
void tst_QWidget::qobject_castInDestroyedSlot()
{
DestroyedSlotChecker checker;
+
QWidget *widget = new QWidget();
QObject::connect(widget, SIGNAL(destroyed(QObject *)), &checker, SLOT(destroyedSlot(QObject *)));
widget.setGeometry(rect);
widget.show();
- QTest::qWaitForWindowShown(&widget);
- QTest::qWait(20);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
if (m_platform == QStringLiteral("windows")) {
QEXPECT_FAIL("130,100 0x200, flags 0", "QTBUG-26424", Continue);
QEXPECT_FAIL("130,50 0x0, flags 0", "QTBUG-26424", Continue);
// show() again, geometry() should still be the same
widget.show();
- QTest::qWaitForWindowShown(&widget);
- QTest::qWait(10);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QTRY_COMPARE(widget.geometry(), rect);
// final hide(), again geometry() should be unchanged
widget.setWindowFlags(Qt::WindowFlags(windowFlags));
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
widget.setGeometry(rect);
QTest::qWait(10);
QTRY_COMPARE(widget.geometry(), rect);
// show() again, geometry() should still be the same
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QTest::qWait(10);
QTRY_COMPARE(widget.geometry(), rect);
// show() again, pos() should be the same
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QApplication::processEvents();
QTRY_COMPARE(widget.pos(), rect.topLeft());
QTRY_COMPARE(widget.size(), rect.size());
widget.setWindowFlags(Qt::WindowFlags(windowFlags));
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QApplication::processEvents();
widget.move(rect.topLeft());
widget.resize(rect.size());
// show() again, pos() should be the same
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QTest::qWait(10);
QTRY_COMPARE(widget.pos(), rect.topLeft());
QTRY_COMPARE(widget.size(), rect.size());
#endif
child.setGeometry(25, 25, 50, 50);
parent.show();
- QTest::qWaitForWindowShown(&parent);
+ QVERIFY(QTest::qWaitForWindowExposed(&parent));
QTest::qWait(30);
const QPoint tlwOffset = parent.geometry().topLeft();
tall->setGeometry(100, 30, 50, 100);
w.show();
- QTest::qWaitForWindowShown(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QTest::qWait(10);
large->reset();
// window and children never shown, nobody gets focus
QWidget window;
+ window.resize(200, 200);
QWidget child1(&window);
child1.setFocusPolicy(Qt::StrongFocus);
{
// window and children show, but window not active, nobody gets focus
QWidget window;
+ window.resize(200, 200);
QWidget child1(&window);
child1.setFocusPolicy(Qt::StrongFocus);
{
// window and children show, but window *is* active, children get focus
QWidget window;
+ window.resize(200, 200);
FocusWidget child1(&window);
child1.setFocusPolicy(Qt::StrongFocus);
window.show();
window.activateWindow();
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
QTRY_VERIFY(qGuiApp->focusWindow());
child1.setFocus();
{
// window shown and active, children created, don't get focus, but get focus when shown
QWidget window;
+ window.resize(200, 200);
window.show();
window.activateWindow();
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
QTRY_VERIFY(qGuiApp->focusWindow());
QWidget child1(&window);
// window shown and active, children created, don't get focus,
// even after setFocus(), hide(), then show()
QWidget window;
+ window.resize(200, 200);
window.show();
window.activateWindow();
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
QTRY_VERIFY(qGuiApp->focusWindow());
QWidget child1(&window);
#ifndef QT_NO_CURSOR
{
QWidget window;
+ window.resize(200, 200);
QWidget child(&window);
QVERIFY(!window.testAttribute(Qt::WA_SetCursor));
// do it again, but with window show()n
{
QWidget window;
+ window.resize(200, 200);
QWidget child(&window);
window.show();
{
QWidget window;
+ window.resize(200, 200);
QWidget child(&window);
window.setCursor(Qt::WaitCursor);
// same thing again, just with window show()n
{
QWidget window;
+ window.resize(200, 200);
QWidget child(&window);
window.show();
// reparenting child should not cause the WA_SetCursor to become set
{
QWidget window;
+ window.resize(200, 200);
QWidget window2;
+ window2.resize(200, 200);
QWidget child(&window);
window.setCursor(Qt::WaitCursor);
// again, with windows show()n
{
QWidget window;
+ window.resize(200, 200);
QWidget window2;
+ window2.resize(200, 200);
QWidget child(&window);
window.setCursor(Qt::WaitCursor);
// Mouse over doesn't work on Windows mobile, so skip the rest of the test for that platform.
#ifndef Q_OS_WINCE_WM
for (int pass = 0; pass < 2; ++pass) {
- QWidget *popup = new QWidget(0, Qt::Popup);
+ QScopedPointer<QWidget> popup(new QWidget(0, Qt::Popup));
popup->resize(150, 50);
- QFrame *frame = new QFrame(popup);
+ QFrame *frame = new QFrame(popup.data());
frame->setGeometry(0, 0, 50, 50);
frame->setFrameStyle(QFrame::Box | QFrame::Plain);
EventSpy spy1(frame, QEvent::ToolTip);
- EventSpy spy2(popup, QEvent::ToolTip);
+ EventSpy spy2(popup.data(), QEvent::ToolTip);
frame->setMouseTracking(pass == 0 ? false : true);
frame->setToolTip(QLatin1String("TOOLTIP FRAME"));
popup->setToolTip(QLatin1String("TOOLTIP POPUP"));
popup->show();
- QTest::qWaitForWindowShown(popup);
+ QVERIFY(QTest::qWaitForWindowExposed(popup.data()));
QTest::qWait(10);
QTest::mouseMove(frame);
QTest::qWait(900); // delay is 700
QCOMPARE(spy2.count(), 0);
if (pass == 0)
QTest::qWait(2200); // delay is 2000
- QTest::mouseMove(popup);
- delete popup;
+ QTest::mouseMove(popup.data());
}
#endif
}
void tst_QWidget::testWindowIconChangeEventPropagation()
{
+ typedef QSharedPointer<EventSpy> EventSpyPtr;
// Create widget hierarchy.
QWidget topLevelWidget;
QWidget topLevelChild(&topLevelWidget);
QCOMPARE(widgets.count(), 4);
// Create spy lists.
- QList <EventSpy *> applicationEventSpies;
- QList <EventSpy *> widgetEventSpies;
+ QList <EventSpyPtr> applicationEventSpies;
+ QList <EventSpyPtr> widgetEventSpies;
foreach (QWidget *widget, widgets) {
- applicationEventSpies.append(new EventSpy(widget, QEvent::ApplicationWindowIconChange));
- widgetEventSpies.append(new EventSpy(widget, QEvent::WindowIconChange));
+ applicationEventSpies.append(EventSpyPtr(new EventSpy(widget, QEvent::ApplicationWindowIconChange)));
+ widgetEventSpies.append(EventSpyPtr(new EventSpy(widget, QEvent::WindowIconChange)));
}
// QApplication::setWindowIcon
for (int i = 0; i < widgets.count(); ++i) {
// Check QEvent::ApplicationWindowIconChange
- EventSpy *spy = applicationEventSpies.at(i);
+ EventSpyPtr spy = applicationEventSpies.at(i);
QWidget *widget = spy->widget();
if (widget->isWindow()) {
QCOMPARE(spy->count(), 1);
}
// Set icon on a top-level widget.
- topLevelWidget.setWindowIcon(*new QIcon);
+ topLevelWidget.setWindowIcon(QIcon());
for (int i = 0; i < widgets.count(); ++i) {
// Check QEvent::ApplicationWindowIconChange
- EventSpy *spy = applicationEventSpies.at(i);
+ EventSpyPtr spy = applicationEventSpies.at(i);
QCOMPARE(spy->count(), 0);
spy->clear();
}
// Cleanup.
- for (int i = 0; i < widgets.count(); ++i) {
- delete applicationEventSpies.at(i);
- delete widgetEventSpies.at(i);
- }
qApp->setWindowIcon(QIcon());
}
window.show();
QApplication::setActiveWindow(&window);
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
QTest::qWait(100);
QCursor::setPos(window.geometry().center());
QTest::qWait(100);
Q_OBJECT
public:
- typedef QList<QPair<QWidget *, QEvent::Type> > EventList;
+ typedef QPair<QWidget *, QEvent::Type> WidgetEventTypePair;
+ typedef QList<WidgetEventTypePair> EventList;
EventRecorder(QObject *parent = 0)
: QObject(parent)
return false;
}
+ static QByteArray msgEventListMismatch(const EventList &expected, const EventList &actual);
+ static QByteArray msgExpectFailQtBug26424(const EventList &expected, const EventList &actual)
+ { return QByteArrayLiteral("QTBUG-26424: ") + msgEventListMismatch(expected, actual); }
+
private:
+ static inline void formatEventList(const EventList &l, QDebug &d);
+
EventList events;
};
+void EventRecorder::formatEventList(const EventList &l, QDebug &d)
+{
+ QWidget *lastWidget = 0;
+ foreach (const WidgetEventTypePair &p, l) {
+ if (p.first != lastWidget) {
+ d << p.first << ':';
+ lastWidget = p.first;
+ }
+ d << p.second << ' ';
+ }
+}
+
+QByteArray EventRecorder::msgEventListMismatch(const EventList &expected, const EventList &actual)
+{
+ QString result;
+ QDebug d = QDebug(&result).nospace();
+ d << "Event list mismatch, expected " << expected.size() << " (";
+ EventRecorder::formatEventList(expected, d);
+ d << "), actual " << actual.size() << " (";
+ EventRecorder::formatEventList(actual, d);
+ d << ')';
+ return result.toLocal8Bit();
+}
+
void tst_QWidget::childEvents()
{
EventRecorder::EventList expected;
<< qMakePair(&widget, QEvent::PolishRequest)
<< qMakePair(&widget, QEvent::Polish)
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1));
- QCOMPARE(spy.eventList(), expected);
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
}
{
<< qMakePair(&widget, QEvent::Show);
expected << qMakePair(&widget, QEvent::ShowToParent);
- QCOMPARE(spy.eventList(), expected);
+
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
spy.clear();
QCoreApplication::sendPostedEvents();
expected << qMakePair(&widget, QEvent::UpdateRequest);
if (m_platform == QStringLiteral("windows") || m_platform == QStringLiteral("xcb"))
- QEXPECT_FAIL("", "QTBUG-26424", Continue);
- QCOMPARE(spy.eventList(), expected);
+ QEXPECT_FAIL("", EventRecorder::msgExpectFailQtBug26424(expected, spy.eventList()).constData(), Continue);
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
}
{
EventRecorder::EventList()
<< qMakePair(&widget, QEvent::ChildAdded)
<< qMakePair(&widget, QEvent::ChildAdded);
- QCOMPARE(spy.eventList(), expected);
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
spy.clear();
QCoreApplication::sendPostedEvents();
<< qMakePair(&widget, QEvent::ChildPolished)
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1))
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2));
- QCOMPARE(spy.eventList(), expected);
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
}
{
<< qMakePair(&widget, QEvent::Show);
expected << qMakePair(&widget, QEvent::ShowToParent);
- QCOMPARE(spy.eventList(), expected);
+
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
spy.clear();
QCoreApplication::sendPostedEvents();
expected << qMakePair(&widget, QEvent::UpdateRequest);
if (m_platform == QStringLiteral("windows") || m_platform == QStringLiteral("xcb"))
- QEXPECT_FAIL("", "QTBUG-26424", Continue);
- QCOMPARE(spy.eventList(), expected);
+ QEXPECT_FAIL("", EventRecorder::msgExpectFailQtBug26424(expected, spy.eventList()).constData(), Continue);
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
}
{
<< qMakePair(&widget, QEvent::ChildPolished)
<< qMakePair(&widget, QEvent::Type(QEvent::User + 1))
<< qMakePair(&widget, QEvent::Type(QEvent::User + 2));
- QCOMPARE(spy.eventList(), expected);
+
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
}
{
<< qMakePair(&widget, QEvent::Show);
expected << qMakePair(&widget, QEvent::ShowToParent);
- QCOMPARE(spy.eventList(), expected);
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
spy.clear();
QCoreApplication::sendPostedEvents();
expected << qMakePair(&widget, QEvent::UpdateRequest);
if (m_platform == QStringLiteral("windows") || m_platform == QStringLiteral("xcb"))
- QEXPECT_FAIL("", "QTBUG-26424", Continue);
- QCOMPARE(spy.eventList(), expected);
+ QEXPECT_FAIL("", EventRecorder::msgExpectFailQtBug26424(expected, spy.eventList()).constData(), Continue);
+ QVERIFY2(spy.eventList() == expected,
+ EventRecorder::msgEventListMismatch(expected, spy.eventList()).constData());
}
}
f.setStyleStrategy(QFont::NoAntialias);
source.setFont(f);
source.show();
- QTest::qWaitForWindowShown(&source);
+ QVERIFY(QTest::qWaitForWindowExposed(&source));
// Render the entire source into target.
RenderWidget target(&source);
// prevent custom styles
window.setStyle(new QWindowsStyle);
window.show();
- QTest::qWaitForWindowShown(&window);
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
QWidget child(&window);
child.resize(window.size());
child.show();
// prevent custom styles
widget.setStyle(new QWindowsStyle);
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QImage image(widget.size(), QImage::Format_RGB32);
image.fill(QColor(Qt::blue).rgb());
if (m_platform == QStringLiteral("xcb"))
QSKIP("QTBUG-26424");
- QCalendarWidget *calendar = new QCalendarWidget;
+ QScopedPointer<QCalendarWidget> calendar(new QCalendarWidget);
// disable anti-aliasing to eliminate potential differences when subpixel antialiasing
// is enabled on the screen
QFont f;
f.setStyleStrategy(QFont::NoAntialias);
calendar->setFont(f);
calendar->show();
- QTest::qWaitForWindowShown(calendar);
+ QVERIFY(QTest::qWaitForWindowExposed(calendar.data()));
// Create a dummy focus widget to get rid of focus rect in reference image.
QLineEdit dummyFocusWidget;
dummyFocusWidget.show();
- QTest::qWaitForWindowShown(&dummyFocusWidget);
+ QVERIFY(QTest::qWaitForWindowExposed(&dummyFocusWidget));
qApp->processEvents();
QTest::qWait(120);
calendar->hide();
qApp->processEvents();
QTest::qWait(30);
- workaroundPaletteIssue(calendar);
+ workaroundPaletteIssue(calendar.data());
{ // Make sure we get the same image when the calendar is explicitly hidden.
QImage testImage(calendarSizeResized, QImage::Format_ARGB32);
// Now that we have reference images we can delete the source and re-create
// the calendar and check that we get the same images from a calendar which has never
// been visible, laid out or created (Qt::WA_WState_Created).
- delete calendar;
- calendar = new QCalendarWidget;
+ calendar.reset(new QCalendarWidget);
calendar->setFont(f);
- workaroundPaletteIssue(calendar);
+ workaroundPaletteIssue(calendar.data());
{ // Never been visible, created or laid out.
QImage testImage(calendarSize, QImage::Format_ARGB32);
}
// Get navigation bar and explicitly hide it.
- QWidget *navigationBar = qFindChild<QWidget *>(calendar, QLatin1String("qt_calendar_navigationbar"));
+ QWidget *navigationBar = qFindChild<QWidget *>(calendar.data(), QLatin1String("qt_calendar_navigationbar"));
QVERIFY(navigationBar);
navigationBar->hide();
#ifdef RENDER_DEBUG
testImage.save("nextMonthButton.png");
#endif
- const QRect buttonRect(nextMonthButton->mapTo(calendar, QPoint()), nextMonthButton->size());
+ const QRect buttonRect(nextMonthButton->mapTo(calendar.data(), QPoint()), nextMonthButton->size());
QCOMPARE(testImage, referenceImage.copy(buttonRect));
// Restore palette.
void tst_QWidget::renderWithPainter()
{
- QWidget widget;
+ QWidget widget(0, Qt::Tool);
// prevent custom styles
widget.setStyle(new QWindowsStyle);
widget.show();
w.setGeometry(60, 60, 110, 110);
#endif
w.show();
- QTest::qWaitForWindowShown(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QTest::qWait(10);
QTRY_COMPARE(w.r, QRegion(w.rect()));
w.r = QRegion();
child2.setGeometry(10, 10, 60, 60);
w.show();
- QTest::qWaitForWindowShown(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QTest::qWait(10);
QTRY_COMPARE(child2.r, QRegion(child2.rect()));
child.r = QRegion();
widget.updateOnActivationChangeAndFocusIn = false;
widget.reset();
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QApplication::processEvents();
QTRY_VERIFY(widget.numPaintEvents > 0);
QTest::qWait(150);
qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QWidget parent;
+ parent.resize(200, 200);
QWidget child(&parent);
QWidget grandChild(&child);
QWidget greatGrandChild(&grandChild);
// Ensure that hide() on an ancestor of a widget with
// Qt::WA_DontCreateNativeAncestors still gets unmapped
QWidget window;
+ window.resize(200, 200);
QWidget widget(&window);
QWidget child(&widget);
child.setAttribute(Qt::WA_NativeWindow);
child.setAttribute(Qt::WA_DontCreateNativeAncestors);
window.show();
- if (m_platform == QStringLiteral("xcb"))
- QEXPECT_FAIL("", "QTBUG-26424", Continue);
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
QVERIFY(child.testAttribute(Qt::WA_Mapped));
widget.hide();
- QVERIFY(!child.testAttribute(Qt::WA_Mapped));
+ QTRY_VERIFY(!child.testAttribute(Qt::WA_Mapped));
}
// Enforce a native window when calling QWidget::winId.
// Make sure we don't create native windows when setting Qt::WA_X11NetWmWindowType attributes
// on alien widgets (see task 194231).
QWidget dummy;
+ dummy.resize(200, 200);
QVERIFY(dummy.winId());
QWidget widget(&dummy);
widget.setAttribute(Qt::WA_X11NetWmWindowTypeToolBar);
{ // Make sure we create native ancestors when setting Qt::WA_PaintOnScreen before show().
QWidget topLevel;
+ topLevel.resize(200, 200);
QWidget child(&topLevel);
QWidget grandChild(&child);
PaintOnScreenWidget greatGrandChild(&grandChild);
{ // Ensure that widgets reparented into Qt::WA_PaintOnScreen widgets become native.
QWidget topLevel;
+ topLevel.resize(200, 200);
QWidget *widget = new PaintOnScreenWidget(&topLevel);
widget->setAttribute(Qt::WA_PaintOnScreen);
QWidget *child = new QWidget;
{ // Ensure that ancestors of a Qt::WA_PaintOnScreen widget stay native
// if they are re-created (typically in QWidgetPrivate::setParent_sys) (task 210822).
QWidget window;
+ window.resize(200, 200);
QWidget child(&window);
QWidget grandChild;
ASWidget(QSize sizeHint, QSizePolicy sizePolicy, bool layout, bool hfwLayout, QWidget *parent = 0)
: QWidget(parent), mySizeHint(sizeHint)
{
+ setObjectName(QStringLiteral("ASWidget"));
+ setWindowTitle(objectName());
setSizePolicy(sizePolicy);
if (layout) {
QSizePolicy sp = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
QFETCH(bool, haveParent);
QFETCH(QSize, expectedSize);
- QWidget *parent = new QWidget;
+ QScopedPointer<QWidget> parent(new QWidget);
QSizePolicy sp = QSizePolicy(QSizePolicy::Policy(hPolicy), QSizePolicy::Policy(vPolicy));
sp.setHeightForWidth(hfwSP);
- QWidget *child = new ASWidget(sizeHint, sp, layout, hfwLayout, haveParent ? parent : 0);
+ QWidget *child = new ASWidget(sizeHint, sp, layout, hfwLayout, haveParent ? parent.data() : 0);
child->resize(123, 456);
child->adjustSize();
if (expectedSize == QSize(100000, 100000)) {
#endif
QCOMPARE(child->size(), expectedSize);
}
-
- delete parent;
+ if (!haveParent)
+ delete child;
}
class TestLayout : public QVBoxLayout
// Show: 1 repaint
int expectedRepaints = 1;
widget.show();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QTest::qWait(10);
if (m_platform == QStringLiteral("windows"))
QEXPECT_FAIL("", "QTBUG-26424", Continue);
// Restore: Should not trigger a repaint.
widget.showNormal();
- QTest::qWaitForWindowShown(&widget);
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
QTest::qWait(10);
QCOMPARE(widget.numPaintEvents, 0);
}
{
QWidget window;
UpdateWidget widget(&window);
+ window.resize(200, 200);
window.show();
qApp->setActiveWindow(&window);
QVERIFY(QTest::qWaitForWindowActive(&window));
testWidget.setMask(QRegion(QRect(0,0,100,10)));
testWidget.show();
w.show();
- QTest::qWaitForWindowShown(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QTest::qWait(30);
QTRY_VERIFY(w.numPaintEvents > 0);
MoveInResizeWidget testWidget;
testWidget.setGeometry(50, 50, 200, 200);
testWidget.show();
- QTest::qWaitForWindowShown(&testWidget);
+ QVERIFY(QTest::qWaitForWindowExposed(&testWidget));
QTest::qWait(300);
QRect expectedGeometry(100,100, 100, 100);
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;
+ QScopedPointer<UpdateWidget> widget(new UpdateWidget);
widget->show();
- QVERIFY(QTest::qWaitForWindowExposed(widget));
+ QVERIFY(QTest::qWaitForWindowExposed(widget.data()));
QTest::qWait(200);
- static_cast<UpdateWidget *>(widget)->numPaintEvents = 0;
+ widget->numPaintEvents = 0;
// Marks the area covered by the widget as dirty in the backing store and
// posts an UpdateRequest event.
- qt_widget_private(widget)->invalidateBuffer(widget->rect());
- QCOMPARE(static_cast<UpdateWidget *>(widget)->numPaintEvents, 0);
+ qt_widget_private(widget.data())->invalidateBuffer(widget->rect());
+ QCOMPARE(widget->numPaintEvents, 0);
// The entire widget is already dirty, but this time we want to update immediately
// by calling repaint(), and thus we have to repaint the widget and not wait for
// the UpdateRequest to be sent when we get back to the event loop.
widget->repaint();
- QCOMPARE(static_cast<UpdateWidget *>(widget)->numPaintEvents, 1);
-
- delete widget;
+ QCOMPARE(widget->numPaintEvents, 1);
}
void tst_QWidget::effectiveWinId()
void tst_QWidget::customDpi()
{
- QWidget *topLevel = new QWidget;
- CustomWidget *custom = new CustomWidget(topLevel);
+ QScopedPointer<QWidget> topLevel(new QWidget);
+ CustomWidget *custom = new CustomWidget(topLevel.data());
QWidget *child = new QWidget(custom);
custom->metricCallCount = 0;
QCOMPARE(custom->metricCallCount, 1);
child->logicalDpiX();
QCOMPARE(custom->metricCallCount, 2);
-
- delete topLevel;
}
void tst_QWidget::customDpiProperty()
{
- QWidget *topLevel = new QWidget;
- QWidget *middle = new CustomWidget(topLevel);
+ QScopedPointer<QWidget> topLevel(new QWidget);
+ QWidget *middle = new CustomWidget(topLevel.data());
QWidget *child = new QWidget(middle);
const int initialDpiX = topLevel->logicalDpiX();
QCOMPARE(child->logicalDpiX(), initialDpiX);
QCOMPARE(child->logicalDpiY(), initialDpiY);
-
- delete topLevel;
}
void tst_QWidget::quitOnCloseAttribute()
void tst_QWidget::moveRect()
{
QWidget widget;
+ widget.resize(200, 200);
widget.setUpdatesEnabled(false);
QWidget child(&widget);
child.setUpdatesEnabled(false);
{
Q_OBJECT
public:
- GDIWidget() { setAttribute(Qt::WA_PaintOnScreen); }
+ GDIWidget() {
+ setAttribute(Qt::WA_PaintOnScreen);
+ timer.setSingleShot(true);
+ timer.setInterval(0);
+ }
QPaintEngine *paintEngine() const { return 0; }
-
void paintEvent(QPaintEvent *) {
QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface();
const HDC hdc = (HDC)ni->nativeResourceForWindow(QByteArrayLiteral("getDC"), windowHandle());
- if (!hdc) {
+ if (hdc) {
+ const HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0));
+ SelectObject(hdc, brush);
+ Rectangle(hdc, 0, 0, 10, 10);
+ DeleteObject(brush);
+ ni->nativeResourceForWindow(QByteArrayLiteral("releaseDC"), windowHandle());
+ } else {
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);
-
- ni->nativeResourceForWindow(QByteArrayLiteral("releaseDC"), windowHandle());
-
- QTimer::singleShot(0, this, SLOT(slotTimer()));
+ if (!timer.isActive()) {
+ connect(&timer, &QTimer::timeout, this,
+ hdc ? &GDIWidget::slotTimer : &QDialog::reject);
+ timer.start();
+ }
}
QSize sizeHint() const {
public:
QColor color;
+ QTimer timer;
};
void tst_QWidget::gdiPainting()
child->setPalette(Qt::red);
child->setAutoFillBackground(true);
child->setAttribute(Qt::WA_StaticContents);
- child->resize(100, 100);
+ child->resize(160, 160);
QWidget *grandChild = new QWidget(child);
grandChild->setPalette(Qt::blue);
grandChild->resize(50, 50);
grandChild->setAttribute(Qt::WA_StaticContents);
window1.show();
- QTest::qWaitForWindowShown(&window1);
+ QVERIFY(QTest::qWaitForWindowExposed(&window1));
QWidget window2;
window2.show();
- QTest::qWaitForWindowShown(&window2);
+ QVERIFY(QTest::qWaitForWindowExposed(&window2));
QTest::qWait(20);
// Reparent into another top-level.
QWidget paintOnScreen;
paintOnScreen.setAttribute(Qt::WA_PaintOnScreen);
paintOnScreen.show();
- QTest::qWaitForWindowShown(&paintOnScreen);
+ QVERIFY(QTest::qWaitForWindowExposed(&paintOnScreen));
QTest::qWait(20);
child->setParent(&paintOnScreen);
mainTools->addWidget(new QLineEdit);
mw.show();
- QTest::qWaitForWindowShown(&mw);
+ QVERIFY(QTest::qWaitForWindowExposed(&mw));
one->setFloating(true);
QTest::qWait(20);
void tst_QWidget::setClearAndResizeMask()
{
UpdateWidget topLevel;
- topLevel.resize(150, 150);
+ topLevel.resize(160, 160);
topLevel.show();
qApp->setActiveWindow(&topLevel);
QVERIFY(QTest::qWaitForWindowActive(&topLevel));
resizeParent.setPalette(pal);
resizeParent.show();
- QTest::qWaitForWindowShown(&resizeParent);
+ QVERIFY(QTest::qWaitForWindowExposed(&resizeParent));
// Disable the size grip on the Mac; otherwise it'll be included when grabbing the window.
resizeParent.setFixedSize(resizeParent.size());
resizeChild.show();
grandChild.setMask(grandChildMask);
topLevel.show();
- QTest::qWaitForWindowShown(&topLevel);
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
QTRY_VERIFY(topLevel.numPaintEvents > 0);
QWidget widget;
QWidget *child = new QWidget(&widget);
- child->resize(100, 100);
+ child->resize(200, 200);
child->setAutoFillBackground(true);
child->setPalette(Qt::red);
QLineEdit w;
w.show();
- QTest::qWaitForWindowShown(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QTest::qWait(20);
QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&w);
w.reset();
w.show();
- QTest::qWaitForWindowShown(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QApplication::processEvents();
QTRY_VERIFY(w.numPaintEvents > 0);
w.reset();
bigWidget->setAutoFillBackground(true);
main.show();
- QTest::qWaitForWindowShown(&main);
+ QVERIFY(QTest::qWaitForWindowExposed(&main));
QPixmap correct(main.size());
correct.fill(Qt::green);
void tst_QWidget::inputFocus_task257832()
{
- QLineEdit *widget = new QLineEdit;
+ QScopedPointer<QLineEdit> widget(new QLineEdit);
widget->setFocus();
widget->winId(); // make sure, widget has been created
widget->show();
QTRY_VERIFY(widget->hasFocus());
- QCOMPARE(qApp->inputMethod()->inputItem(), static_cast<QWidget*>(widget));
+ QCOMPARE(qApp->inputMethod()->inputItem(), widget.data());
widget->setReadOnly(true);
QVERIFY(!qApp->inputMethod()->inputItem());
- delete widget;
}
void tst_QWidget::setGraphicsEffect()
{
// Check that we don't have any effect by default.
- QWidget *widget = new QWidget;
+ QScopedPointer<QWidget> widget(new QWidget);
QVERIFY(!widget->graphicsEffect());
// SetGet check.
blurEffect = new QGraphicsBlurEffect;
// Ensure the effect is uninstalled when setting it on a new target.
- QWidget *anotherWidget = new QWidget;
+ QScopedPointer<QWidget> anotherWidget(new QWidget);
anotherWidget->setGraphicsEffect(blurEffect);
widget->setGraphicsEffect(blurEffect);
QVERIFY(!anotherWidget->graphicsEffect());
QVERIFY(!shadowEffect);
// Ensure the existing effect is deleted when deleting the widget.
- delete widget;
+ widget.reset();
QVERIFY(!blurEffect);
- delete anotherWidget;
+ anotherWidget.reset();
// Ensure the effect is uninstalled when deleting it
- widget = new QWidget;
+ widget.reset(new QWidget);
blurEffect = new QGraphicsBlurEffect;
widget->setGraphicsEffect(blurEffect);
delete blurEffect;
widget->setGraphicsEffect(0);
QVERIFY(!widget->graphicsEffect());
QVERIFY(!blurEffect);
-
- delete widget;
}
void tst_QWidget::activateWindow()
// Test case for task 260685
// Create first mainwindow and set it active
- QMainWindow* mainwindow = new QMainWindow();
- QLabel* label = new QLabel(mainwindow);
+ QScopedPointer<QMainWindow> mainwindow(new QMainWindow);
+ QLabel* label = new QLabel(mainwindow.data());
mainwindow->setCentralWidget(label);
mainwindow->setVisible(true);
mainwindow->activateWindow();
- QTest::qWaitForWindowShown(mainwindow);
- qApp->processEvents();
-
- QTRY_VERIFY(mainwindow->isActiveWindow());
+ QVERIFY(QTest::qWaitForWindowActive(mainwindow.data()));
+ QVERIFY(mainwindow->isActiveWindow());
// Create second mainwindow and set it active
- QMainWindow* mainwindow2 = new QMainWindow();
- QLabel* label2 = new QLabel(mainwindow2);
+ QScopedPointer<QMainWindow> mainwindow2(new QMainWindow);
+ QLabel* label2 = new QLabel(mainwindow2.data());
mainwindow2->setCentralWidget(label2);
mainwindow2->setVisible(true);
mainwindow2->activateWindow();
public:
Widget(QWidget *parent) : QWidget(parent)
{
+ resize(200, 200);
}
~Widget()
{
}
};
- QWidget *win = new QWidget;
- new Widget(win);
+ QScopedPointer<QWidget> win(new QWidget);
+ new Widget(win.data());
win->show();
- QTest::qWaitForWindowShown(win);
- delete win;
+ QVERIFY(QTest::qWaitForWindowExposed(win.data()));
}
void tst_QWidget::focusProxyAndInputMethods()
{
- QWidget *toplevel = new QWidget(0, Qt::X11BypassWindowManagerHint);
+ QScopedPointer<QWidget> toplevel(new QWidget(0, Qt::X11BypassWindowManagerHint));
+ toplevel->resize(200, 200);
toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
- QWidget *child = new QWidget(toplevel);
- child->setFocusProxy(toplevel);
+ QWidget *child = new QWidget(toplevel.data());
+ child->setFocusProxy(toplevel.data());
child->setAttribute(Qt::WA_InputMethodEnabled, true);
toplevel->setFocusPolicy(Qt::WheelFocus);
QVERIFY(!toplevel->hasFocus());
toplevel->show();
- QTest::qWaitForWindowShown(toplevel);
- QApplication::setActiveWindow(toplevel);
- QVERIFY(QTest::qWaitForWindowActive(toplevel));
+ QVERIFY(QTest::qWaitForWindowExposed(toplevel.data()));
+ QApplication::setActiveWindow(toplevel.data());
+ QVERIFY(QTest::qWaitForWindowActive(toplevel.data()));
QVERIFY(toplevel->hasFocus());
QVERIFY(child->hasFocus());
// 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(qApp->inputPanel()->inputItem(), toplevel.data());
toplevel->setAttribute(Qt::WA_InputMethodEnabled, false);
QVERIFY(!qApp->inputPanel()->inputItem());
toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
- QCOMPARE(qApp->inputPanel()->inputItem(), toplevel);
-
- delete toplevel;
+ QCOMPARE(qApp->inputPanel()->inputItem(), toplevel.data());
}
#ifdef QT_BUILD_INTERNAL
void tst_QWidget::scrollWithoutBackingStore()
{
scrollWidgetWBS scrollable;
- scrollable.resize(100,100);
+ scrollable.resize(200, 200);
QLabel child(QString("@"),&scrollable);
child.resize(50,50);
scrollable.show();
- QTest::qWaitForWindowShown(&scrollable);
+ QVERIFY(QTest::qWaitForWindowExposed(&scrollable));
scrollable.scroll(50,50);
QCOMPARE(child.pos(),QPoint(50,50));
scrollable.deleteBackingStore();
QEXPECT_FAIL("", "FixMe, QTBUG-8941 and QTBUG-8977", Abort);
QVERIFY(false);
#else
- QWidget w;
+ // Use Qt::Tool as fully decorated windows have a minimum width of 160 on
+ QWidget w(0, Qt::Tool);
w.show();
QVERIFY(!w.testAttribute(Qt::WA_Moved));
void tst_QWidget::taskQTBUG_11373()
{
- QMainWindow * myWindow = new QMainWindow();
+ QScopedPointer<QMainWindow> myWindow(new QMainWindow);
QWidget * center = new QWidget();
myWindow -> setCentralWidget(center);
- QWidget * drawer = new QWidget(myWindow, Qt::Drawer);
+ QWidget * drawer = new QWidget(myWindow.data(), Qt::Drawer);
drawer -> hide();
QCOMPARE(drawer->isVisible(), false);
myWindow -> show();
tb.setStyleSheet(s);
tb.show();
- QTest::qWaitForWindowShown(&tb);
+ QVERIFY(QTest::qWaitForWindowExposed(&tb));
tb.setGeometry(QRect(100, 100, 0, 100));
// No crash, it works.
}
p1->setAttribute(Qt::WA_NativeWindow);
p2->setAttribute(Qt::WA_NativeWindow);
QApplication::processEvents();
- QTest::qWaitForWindowShown(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QTest::qWait(10);
QCOMPARE(QApplication::activeWindow(), &w);