Window with Qt.Popup not closed
-
I'm trying to create a popup window from within ApplicationWindow. When show() is called on the popup, it is shown, but when I click somewhere on my Desktop or the ApplicationWindow or anywhere else, the popup isn't closed automatically. However, it can be closed by explicitly calling its close() function.
Doesn't work for me on Ubuntu 14.10 (64 bit, Unity) and Windows 7 (64 bit), both with original Nvidia graphics drivers.
Looks like a bug in QtQuick.Window to me, or am I doing it wrong?
@
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480
visible: trueItem { anchors.fill: parent Button { id: button1 text: "Click me" onClicked: mypopup.show() } } Window { id: mypopup flags: Qt.Popup Button { id: button2 text: "Close" onClicked: mypopup.close() } }
}
@ -
Hi,
Yes it is a bug. See "QTBUG-33481":https://bugreports.qt.io/browse/QTBUG-33481.
-
Thanks for the link, p3c0! I have found a way to hack around this. Unfortunately it involves using internal QtQuick features by importing "QtQuick.Controls.Private", but for the moment this is better than nothing :-)
@
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Controls.Private 1.0ApplicationWindow {
id: mainWindow
title: qsTr("Hello World")
width: 640
height: 480
visible: trueproperty var popup: null function togglePopup() { if (popup == null) { popup = Qt.createQmlObject( "import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Window 2.2 import QtQuick.Controls.Private 1.0 PopupWindow { id: mypopup Rectangle { width: 100 height: 100 Button { id: button2 anchors.centerIn: parent text: 'Close' onClicked: dismissPopup() } } }", button1 ) popup.onPopupDismissed.connect( afterPopupDismissed ) popup.x = button1.x + button1.width popup.y = button1.y setTitle( "Popup created" ) popup.show() } else { popup.destroy() popup = null } } function afterPopupDismissed() { popup.destroy() popup = null setTitle( "Popup dismissed" ) } Button { id: button1 text: "Click me" onClicked: togglePopup() }
}
@