Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Loader
Forum Updated to NodeBB v4.3 + New Features

Loader

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 4 Posters 2.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by
    #1

    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!

    E 1 Reply Last reply
    0
    • beeckscheB beecksche

      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!

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @beecksche Loader documentation: "The loaded object can be accessed using the item property." Does that work?

      1 Reply Last reply
      0
      • beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by
        #3

        @Eeli-K
        It is possible to convert the Item to a Popup?

        onShowPopup: {
           popupClose.source = "PopupClose.qml"
           popupClose.item.open() // no access to the open() method
        }
        

        In C++ i usually use qobject_cast.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by dheerendra
          #4

          Can u show the contents of popupclose.qml ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          beeckscheB 1 Reply Last reply
          2
          • dheerendraD dheerendra

            Can u show the contents of popupclose.qml ?

            beeckscheB Offline
            beeckscheB Offline
            beecksche
            wrote on last edited by
            #5

            @dheerendra

            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
                }
            }
            
            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              See the sample code here. Everything should work fine.

              ====main.qml===

              import QtQuick 2.8
              import QtQuick.Window 2.2
              import QtQuick.Controls 2.1

              Window {
              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
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              beeckscheB 1 Reply Last reply
              4
              • dheerendraD dheerendra

                See the sample code here. Everything should work fine.

                ====main.qml===

                import QtQuick 2.8
                import QtQuick.Window 2.2
                import QtQuick.Controls 2.1

                Window {
                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"}
                }

                beeckscheB Offline
                beeckscheB Offline
                beecksche
                wrote on last edited by beecksche
                #7

                @dheerendra
                Thanks it works.
                Just because auto complete doesn't show the open method doesn't mean it won't work.!

                J 1 Reply Last reply
                1
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  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.....

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  1
                  • beeckscheB beecksche

                    @dheerendra
                    Thanks it works.
                    Just because auto complete doesn't show the open method doesn't mean it won't work.!

                    J Offline
                    J Offline
                    Jagh
                    wrote on last edited by Jagh
                    #9

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

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved