QML Popup,屏蔽其他控件,使除了Popup控件的其他控件不再响应

Posted smartvxworks

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QML Popup,屏蔽其他控件,使除了Popup控件的其他控件不再响应相关的知识,希望对你有一定的参考价值。

实现效果:

QML Popup,屏蔽其他控件,使除了Popup控件的其他控件不再响应

策略:

1.让Popup 全屏化展示

width: 1024; height: 768;    //因为我的屏幕就是1024*768分辨率的,所以此时Popup  是全屏显示的,其他控件都在下方,是点不到的

2.背景透明化

background:transparent  // 这里让Popup   的背景透明化,所以其下面的控件是可以看到的,但是是操作不到的

3.设置点击属性

closePolicy :Popup.CloseOnEscape    Popup.CloseOnEscape点击了弹出窗口之外,则点击位置该弹出窗口下方的任何其他层组件,Popup弹窗都不会关闭

4.然后就可以在Popup 里面添加文本框和按钮了,具体见下面代码:

代码实现:

        Popup   //弹出提示框,告知用户照片删除成功
        {
            id: removePicturePopup
            //width: 250; height: 150
            width: 1024; height: 768;                //Popup全屏显示,使下面的控件不可响应,就是点击Popup弹窗其他位置的控件,不进行响应
            background:transparent
            x: picture_Scan_B_Area.width/2-width/2;
            y:picture_Scan_B_Area.height/2-height/2;
            modal:false
            closePolicy :Popup.CloseOnEscape   //Popup.CloseOnEscape点击了弹出窗口之外,则点击位置该弹出窗口下方的任何其他层组件,Popup弹窗都不会关闭,模态弹出窗口通常只有在按下退出键时才会关闭,Popup.CloseOnReleaseOutsideParent当鼠标在其父级之外释放时,弹出窗口将关闭
            Rectangle
            {
                id: removePicturePopupRectangle
                width: 250; height: 150
                x: removePicturePopup.width/2-width/2-30;
                y: removePicturePopup.height/2-height/2;

                Text
                {
                    id:removePicturePopupRectangleText
                    x: removePicturePopupRectangle.width/2-width/2;
                    y: removePicturePopupRectangle.height/2-height/2-30;
                    font.pixelSize: 16
                    text: qsTr("确认是否删除照片?");
                }
                Row
                {
                    x: removePicturePopupRectangle.width/2-width/2;
                    y: removePicturePopupRectangle.height/2-height/2+30
                    spacing: 20
                    Button
                    {
                        text: qsTr("是")
                        font.pixelSize: 16
                        onPressed:
                        {
                            console.log("Popup Button 0")
                            GetDirAllImageLib.deleteFileOrFolder(picture_Scan_D_Area.pictureList[picture_Scan_D_Area.pictureIndex]);  //删除指定文件
                            picture_Scan_B_Area.deleteImage(picture_Scan_D_Area.pictureIndex);  //为了照片缩略图的加载显示
                            removePicturePopup.close();
                        }
                    }
                    Button
                    {
                        text: qsTr("否")
                        font.pixelSize: 16
                        onPressed:
                        {
                            console.log("Popup Button 1")
                            removePicturePopup.close();
                        }
                    }
                }
            }
        }

以上是关于QML Popup,屏蔽其他控件,使除了Popup控件的其他控件不再响应的主要内容,如果未能解决你的问题,请参考以下文章