Combobox弹出窗口打开透明

时间:2016-10-25 08:35:16

标签: qt qml

我有一个Combobox(Control 2.0)。我写自己的组合框就像

Rectangle
{
    border.width: 1
    border.color: "lightsteelblue"
    height:dp(40)
    width: parent.width

    ComboBox {
        id:tmCombo
        model:combotm.datalist
        textRole: "value"
        anchors.fill: parent
        currentIndex:-1;

        contentItem: Text {
            leftPadding: 0
            rightPadding: tmCombo.indicator.width + tmCombo.spacing

            text:tmCombo.currentIndex==-1 ? "":tmCombo.model[tmCombo.currentIndex].value
            font: tmCombo.font
            horizontalAlignment: Text.AlignLeft
            verticalAlignment: Text.AlignVCenter
            elide: Text.ElideRight
        }

        onCurrentIndexChanged: {

            if(currentIndex!=-1) {
                var sqlid=model[currentIndex].sqlid;
                combotm.getsqlid(sqlid,1,Query.SelectSubParam,Query.Subq,"TMC",1);
                TaskResult.taskresult.HatBilgisi_TM=sqlid;
                tmsCombo.enabled=true;         
            }
            else {
                tmsCombo.enabled=false;
            }
            tmsCombo.currentIndex=-1;
        }


    }


}

我的问题是,当Combobox首次打开时,一半弹出窗口是透明的。然后我关闭并再次打开组合框。 Everthing还可以。我在android平台上工作。

解: 我添加了导入QtQuick.Templates 2.0作为T和机会Popup与T.Popup。这项工作

1 个答案:

答案 0 :(得分:1)

Rigth代码是:带有过滤器输入的Combobox :)我有来自C ++端的带有Q_Property的绑定模型。 dp函数是main.qml中的全局函数,它是任何设备的固定像素。

    ComboBox {
                id:trCombo
                model:combotr.datalist
                textRole: "value"
                anchors.fill: parent
                currentIndex:-1;



                contentItem: Text {
                    leftPadding: 0
                    rightPadding: trCombo.indicator.width + trCombo.spacing

                    text:trCombo.currentIndex==-1 ? "":trCombo.model[trCombo.currentIndex].value
                    font: trCombo.font
                    horizontalAlignment: Text.AlignLeft
                    verticalAlignment: Text.AlignVCenter
                    elide: Text.ElideRight
                }

                popup: T.Popup {
                    id:mpopup
                    y: trCombo.height - (trCombo.visualFocus ? 0 : 1)

                    width: trCombo.width
                    implicitHeight: listview.contentHeight
                    topMargin: 6
                    bottomMargin: 6

                // focus: true
                    closePolicy: Popup.NoAutoClose

                    contentItem: Item {


                        Column
                        {
                        anchors.fill: parent
                        spacing: 5
                        TextField
                        {

                        placeholderText: "arama yapın"
                        width: trCombo.width
                        height: dp(35)
                    // color: "red"
                        focus:true
                        inputMethodHints: Qt.ImhNoPredictiveText;

                        onTextChanged:{
                            //console.log("degisiyor");
                            process.filtertr(text);
                        }

                        onAccepted:{
                        //  console.log("Tasarım Bitti");
                            isfinished(true);
                        //  text="";


                        }




                        }

                        ListView {
                        id: listview
                        clip: true
                        model: trCombo.popup.visible ? trCombo.delegateModel : null
                        currentIndex: trCombo.highlightedIndex
                        width: trCombo.width
                        height:dp(500)


                        Rectangle {



                            z: 10
                            parent: listview
                            width: listview.width
                            height: listview.height
                            color: "transparent"
                            border.color: "#bdbebf"
                            layer.smooth: true
                        }

                        ScrollIndicator.vertical: ScrollIndicator { }
                    }

                    }
                }

                    background: Rectangle {  }

                    onClosed: {
                    if(!flag)
                    {
                        mpopup.open();
                    }

                    else
                    flag=false;
                    }


                }


                delegate: ItemDelegate {
                    width: trCombo.width
                    text: trCombo.textRole ? (Array.isArray(trCombo.model) ? modelData[trCombo.textRole] : model[trCombo.textRole]) : modelData
                    font.weight: trCombo.currentIndex === index ? Font.DemiBold : Font.Normal
                    highlighted: trCombo.highlightedIndex == index

                    onClicked: {
                        isfinished(true);
                    }
                }



                onCurrentIndexChanged: {

                    if(currentIndex!=-1)
                    {
                        var sqlid=model[currentIndex].sqlid;
                        combotr.getsqlid(sqlid,1,Query.SelectSubParam,Query.Subq,"TRC",1);
                        TaskResult.taskresult.HatBilgisi_TR=sqlid ;
                        trsCombo.enabled=true;


                    }

                    else
                        trsCombo.enabled=false;

                    trsCombo.currentIndex=-1;
                }


        }