抽屉有一个如此奇怪的行为。在桌面以及仿真器上,它都能正常工作。但是,在我的智能手机上,它无法正常工作。不正确性如下:如果您确实拖动打开,然后按抽屉关闭按钮,则再次按下按钮不会打开抽屉。
Work.qml
import QtQuick 2.4
import QtQuick.Controls 2.0
WorkForm {
property bool isOpened: false
menuButton {
onClicked: {
console.log("isOpened: "+ isOpened);
console.log("drawer.opened: "+ drawer.opened);
if (isOpened){
console.log("drawer close()");
drawer.close();
}
else {
console.log("drawer open()");
drawer.open();
}
}
}
headerSize: 48
Drawer {
id: drawer
dragMargin: 60
y: headerSize
width: 0.4 * parent.width
height: parent.height - headerSize
clip: true
Label {
text: "Content goes here!"
anchors.centerIn: parent
}
onOpened: {
console.log("drawer onOpened");
isOpened = true;
}
onClosed: {
console.log("drawer onClosed");
isOpened = false;
}
}
}
WorkForm.ui.qml
import QtQuick 2.4
import QtQuick.Controls 2.0
Item {
id: uiWelcomeForm
anchors.fill: parent
property color headerColor: "#d73c3c"
property int headerSize: 48
property alias menuButton: menuButton
Rectangle {
id: menuRect
height: headerSize //вставить всюду dpi
color: headerColor
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
//Icon Hamburger
Rectangle {
id: iconHamburger
width: headerSize
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.top: parent.top
color: headerColor
....
MouseArea {
id: menuButton
anchors.fill: parent
}
}
}
}
日志示例(最后一行:已按下按钮,但这不是抽屉的反应):
.....
D libSimpleApp_QML.so: qrc:/Work.qml:16 (onClicked): qml: drawer open()
D libSimpleApp_QML.so: qrc:/Work.qml:37 (onOpened): qml: drawer onOpened
D libSimpleApp_QML.so: qrc:/Work.qml:9 (onClicked): qml: isOpened: true
D libSimpleApp_QML.so: qrc:/Work.qml:10 (onClicked): qml: drawer.opened: false
D libSimpleApp_QML.so: qrc:/Work.qml:12 (onClicked): qml: drawer close()
D libSimpleApp_QML.so: qrc:/Work.qml:41 (onClosed): qml: drawer onClosed
D libSimpleApp_QML.so: qrc:/Work.qml:9 (onClicked): qml: isOpened: false
D libSimpleApp_QML.so: qrc:/Work.qml:10 (onClicked): qml: drawer.opened: false
D libSimpleApp_QML.so: qrc:/Work.qml:16 (onClicked): qml: drawer open()
答案 0 :(得分:0)
使用Popup的closePolicy(从中继承抽屉)并将其设置为Popup.CloseOnEscape | Popup.CloseOnPressOutside