Loader
-
Hello,
i want to load a Popup on demand with the Loader QML Type. But i have no idea how to show the loaded source.Loader { id: popupClose } onShowPopup: { popupClose.source = "PopupClose.qml" // now how do i open the popup ? }
In general i call the open() method of the QML Type Popup, but here i have no access to the method.
Thanks!
-
Can u show the contents of popupclose.qml ?
-
import QtQuick 2.7 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.1 import QtQuick.Window 2.2 Popup { id: popup modal: true focus: true width: 700 height: 250 x: (Screen.desktopAvailableWidth - width) / 2 y: (Screen.desktopAvailableHeight - height) / 2 contentWidth: popup.width contentHeight: popup.height closePolicy: Popup.NoAutoClose ColumnLayout { anchors.fill: parent spacing: 50 Text { font.pixelSize: 20 text: qsTr("Shutdown ...") anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter } ProgressBar { id: progressBarExit anchors.horizontalCenter: parent.horizontalCenter anchors.bottom: parent.bottom anchors.bottomMargin: 20 Layout.width: parent.width - 50 property real max: 300 property int current: 0 Timer { id: timerExit interval: 100; running: false; repeat: true onTriggered: progressBarExit.value = ++progressBarExit.current / progressBarExit.max } } } Connections { target: popup onOpened: timerExit.running = true } }
-
See the sample code here. Everything should work fine.
====main.qml===
import QtQuick 2.8
import QtQuick.Window 2.2
import QtQuick.Controls 2.1Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")Button { text: "Open" onClicked: { ld.source = "MyPopup.qml" ld.item.open(); } } Loader { id : ld }
}
====MyPopup.qml======
Popup {
id: popup
x: 100
y: 100
width: 200
height: 300
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
contentItem: Rectangle{width: 100;height: 100;color :"blue"}
} -
@dheerendra
Thanks it works.
Just because auto complete doesn't show the open method doesn't mean it won't work.! -
LOL.. qtcreator is not single source of truth of class. Qt documentation and qt source is single source of truth. So auto complete is just editor feature.....
-
@beecksche JavaScript is dynamically typed language, so there is no need to convert static variable types(there are no static types of a variable).
Which also means that autocompletion often doesn't know what type something is.(and it's ok)