Search code examples
qtqt5qtquick2qt-quickqtquickcontrols2

QtQuick Templates popup vs QtQuick Controls popup


What is the difference between a Qt Quick Templates popup vs QtQuick Controls popup?

The popups I get from import QtQuick.Templates 2.0 vs import QtQuick.Controls 2.0 seem to have minor behavior differences.

[1] https://doc-snapshots.qt.io/qt5-5.8/qml-qtquick-controls2-popup.html

[2] http://doc.qt.io/qt-5/qtquick-templates2-qmlmodule.html


Solution

  • The templates are just the logical skeleton of the actual controls without the graphical parts, the popup from controls is just a decorated version of the popup from templates:

    //Popup.qml
    import QtQuick 2.6
    import QtQuick.Templates 2.0 as T
    
    T.Popup {
        id: control
    
        implicitWidth: Math.max(background ? background.implicitWidth : 0,
                                contentWidth > 0 ? contentWidth + leftPadding + rightPadding : 0)
        implicitHeight: Math.max(background ? background.implicitHeight : 0,
                                 contentWidth > 0 ? contentHeight + topPadding + bottomPadding : 0)
    
        contentWidth: contentItem.implicitWidth || (contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0)
        contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0)
    
        padding: 12
    
        contentItem: Item { }
    
        background: Rectangle {
            border.color: "#353637"
        }
    }
    

    So there shouldn't really be any behavioral differences.