QML中一个组件中声明不同的模块版本,作用功能也会发生变化,那么直接举了例子,更容易理解
import QtQuick 2.7
import QtQuick.Controls 1.0
Menu {
id: insertMenu
width: 124
height: 36
MenuItem {
width: 124
height: 36
Rectangle{
id:box
anchors.fill: parent
color: "#035E88"
}
Text {
text: qsTr("添加标签")
anchors.centerIn: box
font.family: weiMihei.name
font.pixelSize: 20
color: "white"
}
}
}
在上述代码中会出现报错,提示 width和 height是不可用的,如果换成import QtQuick.Controls 2.2,它就是可用的,如果直接改,组件中其他的控件又会报错,那么可以使用下面方式解决
import QtQuick 2.7
import QtQuick.Controls 1.0
import QtQuick.Controls 2.2 as Controls2
Controls2. Menu {
id: insertMenu
width: 124
height: 36
Controls2. MenuItem {
width: 124
height: 36
Rectangle{
id:box
anchors.fill: parent
color: "#035E88"
}
Text {
text: qsTr("添加标签")
anchors.centerIn: box
font.family: weiMihei.name
font.pixelSize: 20
color: "white"
}
}
}