Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Custom QML objects



  • Hi! :) How to create new objects in QML, utilizing all benefits of programming in object-oriented environment? I want to create a class inheriting Popup with ability of displaying short videos while hover some element in application window. Thanks in advance.


  • Moderators

    @Tikani

    How to create new objects in QML, utilizing all benefits of programming in object-oriented environment?

    Please refer http://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html

    I want to create a class inheriting Popup with ability of displaying short videos while hover some element in application window.

    You can create a custom component which will instantiate Popup. In this custom component you can add your own properties and methods which will be accessible when you instantiate your custom component.
    For eg.:
    MyPopup.qml

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    
    Popup {
        property string property1: "abc"
        property bool property2: true
        property int property3: 100
    
        x: 100
        y: 100
        width: 200
        height: 300
        modal: true
        focus: true
        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
    }
    

    Using MyPopup

    Window {
        id: window
        width: 400
        height: 400
        visible: true
    
        Button {
            text: "Open"
            onClicked: popup.open()
        }
    
        MyPopup {
            id: popup
        }
    }
    

Log in to reply