【问题标题】:QtQuick Templates popup vs QtQuick Controls popupQtQuick 模板弹出窗口与 QtQuick 控件弹出窗口
【发布时间】:2016-12-16 01:45:04
【问题描述】:

Qt Quick Templates 弹出窗口与 QtQuick Controls 弹出窗口有什么区别?

我从import QtQuick.Templates 2.0import QtQuick.Controls 2.0 得到的弹出窗口似乎有细微的行为差异。

[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

【问题讨论】:

    标签: qt qt5 qtquick2 qt-quick qtquickcontrols2


    【解决方案1】:

    模板只是没有图形部分的实际控件的逻辑骨架,控件的弹出窗口只是模板弹出窗口的修饰版本:

    //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"
        }
    }
    

    所以实际上不应该有任何行为差异。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多