Suppress the modal window handling for dialogs embedded into QGraphicsView.
A dialog embedded into QGraphicsView has Qt::WA_DontShowOnScreen set (similar to a native dialog). It must not trigger the modal handling though as not to lock up. Task-number: QTBUG-49124 Change-Id: I22ce3f18d01df017b9317666770686bd4491387f Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>bb10
parent
1c01cfa077
commit
3dbdc367ff
|
|
@ -7876,8 +7876,9 @@ void QWidgetPrivate::show_sys()
|
|||
if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
|
||||
invalidateBuffer(q->rect());
|
||||
q->setAttribute(Qt::WA_Mapped);
|
||||
if (q->isWindow() && q->windowModality() != Qt::NonModal && window) {
|
||||
// add our window to the modal window list
|
||||
// add our window the modal window list (native dialogs)
|
||||
if ((q->isWindow() && (!extra || !extra->proxyWidget))
|
||||
&& q->windowModality() != Qt::NonModal && window) {
|
||||
QGuiApplicationPrivate::showModalWindow(window);
|
||||
}
|
||||
return;
|
||||
|
|
@ -8008,8 +8009,9 @@ void QWidgetPrivate::hide_sys()
|
|||
|
||||
if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
|
||||
q->setAttribute(Qt::WA_Mapped, false);
|
||||
if (q->isWindow() && q->windowModality() != Qt::NonModal && window) {
|
||||
// remove our window from the modal window list
|
||||
// remove our window from the modal window list (native dialogs)
|
||||
if ((q->isWindow() && (!extra || !extra->proxyWidget))
|
||||
&& q->windowModality() != Qt::NonModal && window) {
|
||||
QGuiApplicationPrivate::hideModalWindow(window);
|
||||
}
|
||||
// do not return here, if window non-zero, we must hide it
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QSizeGrip>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QGraphicsView>
|
||||
#include <QWindow>
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
|
@ -80,6 +82,7 @@ private slots:
|
|||
void snapToDefaultButton();
|
||||
void transientParent_data();
|
||||
void transientParent();
|
||||
void dialogInGraphicsView();
|
||||
|
||||
private:
|
||||
QDialog *testWidget;
|
||||
|
|
@ -118,9 +121,11 @@ public:
|
|||
class ToolDialog : public QDialog
|
||||
{
|
||||
public:
|
||||
ToolDialog(QWidget *parent = 0) : QDialog(parent, Qt::Tool), mWasActive(false), tId(-1) {
|
||||
}
|
||||
ToolDialog(QWidget *parent = 0)
|
||||
: QDialog(parent, Qt::Tool), mWasActive(false), mWasModalWindow(false), tId(-1) {}
|
||||
|
||||
bool wasActive() const { return mWasActive; }
|
||||
bool wasModalWindow() const { return mWasModalWindow; }
|
||||
|
||||
int exec() {
|
||||
tId = startTimer(300);
|
||||
|
|
@ -131,12 +136,14 @@ protected:
|
|||
if (tId == event->timerId()) {
|
||||
killTimer(tId);
|
||||
mWasActive = isActiveWindow();
|
||||
mWasModalWindow = QGuiApplication::modalWindow() == windowHandle();
|
||||
reject();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int mWasActive;
|
||||
bool mWasModalWindow;
|
||||
int tId;
|
||||
};
|
||||
|
||||
|
|
@ -616,5 +623,27 @@ void tst_QDialog::transientParent()
|
|||
QCOMPARE(dialog.windowHandle()->transientParent(), topLevel.windowHandle());
|
||||
}
|
||||
|
||||
void tst_QDialog::dialogInGraphicsView()
|
||||
{
|
||||
// QTBUG-49124: A dialog embedded into QGraphicsView has Qt::WA_DontShowOnScreen
|
||||
// set (as has a native dialog). It must not trigger the modal handling though
|
||||
// as not to lock up.
|
||||
QGraphicsScene scene;
|
||||
QGraphicsView view(&scene);
|
||||
view.setWindowTitle(QTest::currentTestFunction());
|
||||
const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
|
||||
view.resize(availableGeometry.size() / 2);
|
||||
view.move(availableGeometry.left() + availableGeometry.width() / 4,
|
||||
availableGeometry.top() + availableGeometry.height() / 4);
|
||||
ToolDialog *dialog = new ToolDialog;
|
||||
scene.addWidget(dialog);
|
||||
view.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
dialog->exec();
|
||||
QVERIFY(!dialog->wasModalWindow());
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QDialog)
|
||||
#include "tst_qdialog.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue