解决QML 虚拟键盘被弹出窗口挡住 InputPanel covered by Popup

QT版本:5.12.9,已装VirtualKeyboard插件

我的main.qml类似如下,

重点是这三个部分:

z,怕不保险可以设置99

parent: Overlay.overlay   //很关键,直接照着复制

focus:也不一定要用true,可以自己设置状态变化来改变

z: 1
parent: Overlay.overlay
focus: true
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.VirtualKeyboard 2.4
import QtQuick.Controls 2.5
import QtGraphicalEffects 1.12


Window {
    id: window
    visible: true
    width: SCREEN_WIDTH
    height: SCREEN_HEIGHT

    Item {
        id: itemMain
        rotation: IS_ARM ? 90 : 0
        width: IS_ARM ? parent.height : parent.width
        height: IS_ARM ? parent.width : parent.height
       
        InputPanel {
            id: inputPanel
            width: parent.width
            z: 99
//            z:1
            y:parent.height
            //不加这句话,键盘会被popup挡住
            parent: Overlay.overlay
            states: State {
                name: "visible"
                when: inputPanel.active
                PropertyChanges {
                    target: inputPanel
                    y: itemMain.height - inputPanel.height
                }
            }
            transitions: Transition {
                from: ""
                to: "visible"
                reversible: true
                ParallelAnimation {
                    NumberAnimation {
                        properties: "y"
                        duration: 250
                        easing.type: Easing.InOutQuad
                    }
                }
            }
        }
    }
}

然后我的子页面里有个Popup,属性设置大概如下:

重点就是:

modal:false //模态必须为false,允许其他控件作用

modal: false      
focus: true
Popup {
        id: ipPopup
        anchors.centerIn: parent
        width: parent.width-70
        height: parent.height/4*3
        modal: false
        focus: true
        closePolicy: "NoAutoClose"
        background:Rectangle{
            anchors.fill: parent
            border.color: "#1DEDD7"
            border.width: 2
            radius:5
            gradient: Gradient {
                GradientStop { position: 0.0; color: "#103D2C" }
                GradientStop { position: 1.0; color: "#071F14" }
            }
            Image {
                source: "../images/setup/USBPopupbg.png"
                width: parent.width
                height: 160
                anchors.bottom: parent.bottom
            }
            Button{
                id:btnClose
                anchors.top: parent.top
                anchors.right: parent.right
                anchors.margins: 8
                width: 30
                height: 30
                background: Rectangle{
                    color: "transparent"
                    Image{
                        source: "qrc:/images/setup/USBPopupbg10.png"
                        anchors.fill: parent
                    }
                }
                onClicked: ipPopup.close()
            }
        }
        Text {
            id:ipTitle
            text: "IP设置"
            font.pixelSize: 32
            font.family: "SourceHanSansCN-Bold"
            color: "#FFFFFF"
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
            anchors.topMargin: 60
            horizontalAlignment: Text.AlignHCenter
        }
        Text {
            id: currentAddress
            text: qsTr("当前地址:")
            anchors.top: ipTitle.bottom
            anchors.topMargin: ipTitle.height*2
            anchors.left: parent.left
            anchors.leftMargin: 90
            color: "white"
            font.pixelSize: 24
            font.family: "SourceHanSansCN-Regular"
        }
        Rectangle{
            id:currentAddressValue
            width: 370
            color: "transparent"
            anchors.verticalCenter: currentAddress.verticalCenter
            anchors.left: currentAddress.right
            anchors.leftMargin: 5
            Image{
                source: "qrc:/images/setup/组 17.png"
                anchors.fill: parent
            }
            Text{
                text: "192.168.1.1"
                anchors.left: parent.left
                anchors.leftMargin: 5
                anchors.verticalCenter: parent.verticalCenter
                color: "white"
                font.pixelSize: 24
                font.family: "SourceHanSansCN-Regular"
            }
        }
        Text {
            id: dhcp
            text: qsTr("DHCP配置:")
            anchors.top: currentAddress.bottom
            anchors.topMargin: 70
            anchors.right: currentAddress.right
            color: "white"
            font.pixelSize: 24
            font.family: "SourceHanSansCN-Regular"
        }
        Row{
            anchors.verticalCenter: dhcp.verticalCenter
            anchors.left: dhcp.right
            anchors.leftMargin: 5
            RadioButton{
                checked:true
                text: qsTr("启用")
            }
            RadioButton{
                checked:false
                text: qsTr("关闭")
            }
        }
        Text {
            id: ipAddress
            text: qsTr("IP地址:")
            anchors.top: dhcp.bottom
            anchors.topMargin: 70
            anchors.right: currentAddress.right
            color: "white"
            font.pixelSize: 24
            font.family: "SourceHanSansCN-Regular"
        }
        TextField{
            id:ipAddressInput
            width: 370
            height: 55
            placeholderText: "请输入"
            placeholderTextColor: "white"
            font.pixelSize: 20
            font.bold: true
            color: "white"
            anchors.left: ipAddress.right
            anchors.leftMargin: 5
            anchors.verticalCenter: ipAddress.verticalCenter
            maximumLength: 40
            horizontalAlignment: "AlignLeft"
            background: Image {
                source: "qrc:/images/setup/组 17.png"
            }
        }
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值