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>
This commit is contained in:
Friedemann Kleint 2015-01-19 16:57:20 +01:00
parent df3ffeec15
commit 239f67f158
2 changed files with 48 additions and 4 deletions

View File

@ -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) {

View File

@ -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"