summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-01-19 16:57:20 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-02-05 13:54:01 +0000
commit239f67f158c55d3eb88348a53b87fa272402c733 (patch)
tree714ac81bcf473c077f085ccbcbe3f0d8e993bb12
parentdf3ffeec15cd20c249cb6ffb2d235526a05722a5 (diff)
Do not close popup widgets when showing a widget embedded into QGraphicsView.
Disable top-level widget code path for embedded widget in the show helper. Task-number: QTBUG-43780 Change-Id: I574e07130e5e68a019a426cee3fde982f3883720 Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
-rw-r--r--src/widgets/kernel/qwidget.cpp13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp39
2 files changed, 48 insertions, 4 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 453a7ca537..d8b8b151c2 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -7738,10 +7738,17 @@ void QWidgetPrivate::show_helper()
+ const bool isWindow = q->isWindow();
+#ifndef QT_NO_GRAPHICSVIEW
+ bool isEmbedded = isWindow && q->graphicsProxyWidget() != Q_NULLPTR;
+#else
+ bool isEmbedded = false;
+#endif
+
// popup handling: new popups and tools need to be raised, and
// existing popups must be closed. Also propagate the current
// windows's KeyboardFocusChange status.
- if (q->isWindow()) {
+ if (isWindow && !isEmbedded) {
if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) {
q->raise();
if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange))
@@ -7756,10 +7763,8 @@ void QWidgetPrivate::show_helper()
// Automatic embedding of child windows of widgets already embedded into
// QGraphicsProxyWidget when they are shown the first time.
- bool isEmbedded = false;
#ifndef QT_NO_GRAPHICSVIEW
- if (q->isWindow()) {
- isEmbedded = q->graphicsProxyWidget() ? true : false;
+ if (isWindow) {
if (!isEmbedded && !bypassGraphicsProxyWidget(q)) {
QGraphicsProxyWidget *ancestorProxy = nearestGraphicsProxyWidget(q->parentWidget());
if (ancestorProxy) {
diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index 66d0f64ceb..5aea845f90 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
@@ -175,6 +175,7 @@ private slots:
void windowFrameMargins();
void QTBUG_6986_sendMouseEventToAlienWidget();
void mapToGlobal();
+ void QTBUG_43780_visibility();
};
// Subclass that exposes the protected functions.
@@ -278,6 +279,8 @@ void tst_QGraphicsProxyWidget::initTestCase()
// Disable menu animations to prevent the alpha widget from getting in the way
// in actionsContextMenu().
QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false);
+ // Disable combo for QTBUG_43780_visibility()/Windows Vista.
+ QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false);
}
// This will be called after the last test function is executed.
@@ -3687,5 +3690,41 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135
.arg(embeddedCenterGlobal.x()).arg(embeddedCenterGlobal.y())));
}
+// QTBUG_43780: Embedded widgets have isWindow()==true but showing them should not
+// trigger the top-level widget code path of show() that closes all popups
+// (for example combo popups).
+void tst_QGraphicsProxyWidget::QTBUG_43780_visibility()
+{
+ const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
+ const QSize size = availableGeometry.size() / 4;
+ QWidget mainWindow;
+ QVBoxLayout *layout = new QVBoxLayout(&mainWindow);
+ QComboBox *combo = new QComboBox(&mainWindow);
+ combo->addItems(QStringList() << "i1" << "i2" << "i3");
+ layout->addWidget(combo);
+ QGraphicsScene *scene = new QGraphicsScene(&mainWindow);
+ QGraphicsView *view = new QGraphicsView(scene, &mainWindow);
+ layout->addWidget(view);
+ mainWindow.setWindowTitle(QTest::currentTestFunction());
+ mainWindow.resize(size);
+ mainWindow.move(availableGeometry.topLeft()
+ + QPoint(availableGeometry.width() - size.width(),
+ availableGeometry.height() - size.height()) / 2);
+ QLabel *label = new QLabel(QTest::currentTestFunction());
+ scene->addWidget(label);
+ label->hide();
+ mainWindow.show();
+ combo->setFocus();
+ mainWindow.activateWindow();
+ QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
+ combo->showPopup();
+ QWidget *comboPopup = combo->view()->window();
+ QVERIFY(comboPopup);
+ QVERIFY(QTest::qWaitForWindowExposed(comboPopup));
+ label->show();
+ QTRY_VERIFY(label->isVisible());
+ QVERIFY(comboPopup->isVisible());
+}
+
QTEST_MAIN(tst_QGraphicsProxyWidget)
#include "tst_qgraphicsproxywidget.moc"