查看完整版本: [-- QML中日期控件被其他元素遮挡 --]

QTCN开发网 -> Qt QML开发 -> QML中日期控件被其他元素遮挡 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

北城 2016-06-06 14:42

QML中日期控件被其他元素遮挡

我写了一个日历控件,在应用程序中使用,被其他元素遮挡。不知道是布局的问题还是设置最上层的问题。我用z属性设置元素最上层,但是没起作用。求大牛们指点下。

北城 2016-06-06 15:47
/**************************************
  *文件名:TimeEdit.qml
  ***************************************/
import QtQuick 2.3
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
import QtQml 2.2
import QtQuick.Controls.Styles 1.4

//TimeEdit组件
Rectangle {
    id:rectange
    width: 100
    height: 25
    //z:window.z + 1

    /**********************************自定义属性***********************************/
    property alias text: textEdit.strTime     //保存当前的时间文本
    property date currentDate: new Date()
    property bool isFull: true
    /***********************************对象树*************************************/
    //自定义的时间输入框组件
    TimeInput{
        id:textEdit
        width: parent.width
        height: parent.height
        anchors.top: parent.top
        anchors.left: parent.left
    }

    //日历控件
    Calendar{
        id:calendarItem
        width: parent.width
        height: 250

        z: window.z + 1

//        parent: window.contentItem
//        z: focusShade.z

        anchors.top: textEdit.bottom
        anchors.left: textEdit.left

        visible: false

        onClicked: {
//            calendarItem.raise()
//            progressBar1.raise()
            visible:false
        }

北城 2016-06-06 15:48
1楼是日历的实现。下面代码是在main.qml中的使用
                RowLayout {
                    id:rowLayout4
                    spacing: 5

                    //类似于spinbox的时间控件
//                    DateInput {
//                        id:dataInput1
//                        width:150
//                    }

                    TimeEdit {
                        id:timeInput0
                        isFull: false
                        Layout.fillWidth: true

                        //z:window.z +1
                        //width: 150
                    }

                    TimeEdit {
                        id:timeInput1
                        isFull: true
                        Layout.fillWidth: true

                        //z:window.z +1
                      }
}

马侬骑士 2016-06-12 19:38
可以运行,没有遮挡,不知道为何要Calendar控件中 visible: false
        onClicked: {
//            calendarItem.raise()
//            progressBar1.raise()
            visible:false
        }
这样写是不对的,不是属性绑定了,这个属于JAVAESCA了,要
        onClicked: {
//            calendarItem.raise()
//            progressBar1.raise()
            visible = false
        }
感觉应该是ture
太奇怪了,不知道想干什么


查看完整版本: [-- QML中日期控件被其他元素遮挡 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled