From bc7851d6d4a179b2ebdc76d23d353deddbd9a426 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 5 Jan 2016 14:15:27 +0100 Subject: [PATCH] Reproduce QTBUG-50206 with hierarchy example. - Launch testcon.exe {D574A747-8016-46DB-A07C-B2B4854EE75C} - (HighDPI scaling off) - Move testcon to screen 2 - Press dialog button Task-number: QTBUG-50206 Change-Id: I0f11eb596a3071cd9ef020447aa319d8b10bec49 --- examples/activeqt/hierarchy/hierarchy.pro | 6 ++ examples/activeqt/hierarchy/main.cpp | 1 + examples/activeqt/hierarchy/objects.cpp | 121 ++++++++++++++++++++++++++++++ examples/activeqt/hierarchy/objects.h | 4 + 4 files changed, 132 insertions(+) diff --git a/examples/activeqt/hierarchy/hierarchy.pro b/examples/activeqt/hierarchy/hierarchy.pro index acc108a..27c209c 100644 --- a/examples/activeqt/hierarchy/hierarchy.pro +++ b/examples/activeqt/hierarchy/hierarchy.pro @@ -14,3 +14,9 @@ DEF_FILE = hierarchy.def # install target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/hierarchy INSTALLS += target + +DIAGLIB = +exists($$(QTDIR)):DIAGLIB = $$(QTDIR)/tests/manual/diaglib +# Building against Qt4 or QTDIR not set: +!exists($$DIAGLIB):DIAGLIB=d:/dev/5-vs15-56/qt-56/qtbase/tests/manual/diaglib +exists($$DIAGLIB):include($$DIAGLIB/diaglib.pri) diff --git a/examples/activeqt/hierarchy/main.cpp b/examples/activeqt/hierarchy/main.cpp index 817998e..47879ea 100644 --- a/examples/activeqt/hierarchy/main.cpp +++ b/examples/activeqt/hierarchy/main.cpp @@ -42,6 +42,7 @@ #include "objects.h" #include +// {D574A747-8016-46DB-A07C-B2B4854EE75C} QAXFACTORY_BEGIN("{9e626211-be62-4d18-9483-9419358fbb03}", "{75c276de-1df5-451f-a004-e4fa1a587df1}") QAXCLASS(QParentWidget) QAXTYPE(QSubWidget) diff --git a/examples/activeqt/hierarchy/objects.cpp b/examples/activeqt/hierarchy/objects.cpp index 1cb59ae..df218bd 100644 --- a/examples/activeqt/hierarchy/objects.cpp +++ b/examples/activeqt/hierarchy/objects.cpp @@ -41,13 +41,82 @@ #include "objects.h" #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef QT_DIAG_LIB +# include +# include +# include +#endif /* Implementation of QParentWidget */ //! [0] QParentWidget::QParentWidget(QWidget *parent) : QWidget(parent) { + setObjectName("AxQParentWidget"); + + QVBoxLayout *bl = new QVBoxLayout; + QVBoxLayout *dbl = 0; + QPushButton *pb = new QPushButton("Dump", this); + pb->setObjectName("AxDumpButton"); + bl->addWidget(pb); + connect(pb, &QPushButton::clicked, + this, &QParentWidget::dump); + + pb = new QPushButton("MapToGlobal", this); + pb->setObjectName("AxMapToGlobalButton"); + bl->addWidget(pb); + connect(pb, &QPushButton::clicked, this, &QParentWidget::mapToGlobalTest); + +#ifdef QT_DIAG_LIB + dbl = new QVBoxLayout; + pb = new QPushButton("Dump Widgets", this); + pb->setObjectName("AxDumpWidgetsButton"); + dbl->addWidget(pb); + connect(pb, &QPushButton::clicked, this, [] () { QtDiag::dumpAllWidgets(); } ); + + pb = new QPushButton("Dump Windows", this); + pb->setObjectName("AxDumpWindowsButton"); + dbl->addWidget(pb); + connect(pb, &QPushButton::clicked, this, [] () { QtDiag::dumpAllWindows(); } ); + + pb = new QPushButton("Dump Native Windows", this); + pb->setObjectName("AxDumpNativeWindowsButton"); + dbl->addWidget(pb); + connect(pb, &QPushButton::clicked, this, [] () { QtDiag::dumpNativeWindows(); } ); + +#endif + + pb = new QPushButton("Dialog", this); + pb->setObjectName("AxDialogButton"); + bl->addWidget(pb); + connect(pb, &QPushButton::clicked, + this, &QParentWidget::showDialog); + + pb = new QPushButton("Positioned Dialog", this); + pb->setObjectName("AxPosDialogButton"); + bl->addWidget(pb); + connect(pb, &QPushButton::clicked, + this, &QParentWidget::showDialogMapToGlobal); + + QHBoxLayout *hl = new QHBoxLayout; + hl->addLayout(bl); + if (dbl) + hl->addLayout(dbl); + hl->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored)); vbox = new QVBoxLayout(this); + QLabel *il = new QLabel(QLibraryInfo::build()); + il->setWordWrap(true); + vbox->addWidget(il); + vbox->addLayout(hl); + vbox->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); } //! [0] //! [1] @@ -65,6 +134,57 @@ QSubWidget *QParentWidget::subWidget(const QString &name) return findChild(name); } +void QParentWidget::dump() +{ + QDebug d = qDebug(); + d.setVerbosity(3); + const QWindow *qwin = windowHandle(); + d << '>' << __FUNCTION__ << "\nQWidget: " + << this << '\n' + << "Size: min=" << minimumSize() << "hint=" << sizeHint() + << "max=" << maximumSize() + << "\n\nQWindow:" << qwin; + if (qwin) + d << "\n\nQScreen" << qwin->screen(); + d << '\n'; +} + +void QParentWidget::mapToGlobalTest() +{ + const QPoint g = mapToGlobal(QPoint()); + qDebug() << "gl=" << g << mapFromGlobal(g); +} + +class TestDialog : public QDialog { +public: + TestDialog(QWidget *p = 0); +}; + +TestDialog::TestDialog(QWidget *p) : QDialog(p) +{ + setModal(false); + setAttribute(Qt::WA_DeleteOnClose); + setObjectName("AxDialog"); + QVBoxLayout *lt = new QVBoxLayout(this); + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close, this); + lt->addWidget(bb); + connect(bb, SIGNAL(rejected()), this, SLOT(reject())); +} + +void QParentWidget::showDialog() +{ + TestDialog *dialog = new TestDialog(this); + dialog->show(); +} + +void QParentWidget::showDialogMapToGlobal() +{ + TestDialog *dialog = new TestDialog(this); + const QPoint tl = mapToGlobal(QPoint()); + dialog->move(tl); + dialog->show(); +} + //! [2] QSize QParentWidget::sizeHint() const { @@ -99,6 +219,7 @@ QSize QSubWidget::sizeHint() const void QSubWidget::paintEvent(QPaintEvent *) { + qDebug(__FUNCTION__); QPainter painter(this); painter.setPen(palette().text().color()); painter.drawText(rect(), Qt::AlignCenter, lbl); diff --git a/examples/activeqt/hierarchy/objects.h b/examples/activeqt/hierarchy/objects.h index 4ceea1f..335ad48 100644 --- a/examples/activeqt/hierarchy/objects.h +++ b/examples/activeqt/hierarchy/objects.h @@ -62,6 +62,10 @@ public: public slots: void createSubWidget( const QString &name ); + void dump(); + void mapToGlobalTest(); + void showDialog(); + void showDialogMapToGlobal(); QSubWidget *subWidget( const QString &name ); -- 2.5.0.windows.1