组合框元素中的白色间距

时间:2018-06-08 16:06:13

标签: qt combobox qml

我正在定制Combobox。这是我的代码:

import QtQuick 2.7
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls 2.2
import QtQuick.Window 2.2

ComboBox {
    property int selectionButtonWidth: 35
    property int selectionButtonHeight: 25
    property int selectionButtonFontSize: 12
    property string mainFontFamily: "Asap"
    property color mainFontColor: "red"
    property color inputHighlight: "#9C27B0"
    property color comboboxBorderColor: "#C5C1CD"
    property int comboboxBorderWidth: 1

    id: playFromHour
    width: selectionButtonWidth
    height: selectionButtonHeight

    model: 24
    currentIndex: 1

    font.family: mainFontFamily
    font.pixelSize: selectionButtonFontSize

    property bool needHighlight: false

    onNeedHighlightChanged: {
        if (needHighlight) {
            playFromHourBack.border.color = inputHighlight
        }
        else {
            playFromHourBack.border.color = comboboxBorderColor
        }
    }

    background: Rectangle {
        id: playFromHourBack
        color: "transparent"
        border.color: comboboxBorderColor
        border.width: comboboxBorderWidth
    }

    contentItem: Text {
        text: parent.displayText
        font: parent.font
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        color: mainFontColor
    }

    indicator: Canvas {
    }

    delegate: ItemDelegate {
        width: parent.width
        height: selectionButtonHeight

        contentItem: Text {
            text: modelData
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            font: playFromHour.font
            color: mainFontColor
        }

        highlighted: playFromHour.highlightedIndex === index
    }

    popup: Popup {
        width: selectionButtonWidth
        height: 6 * selectionButtonHeight

        contentItem: ListView {
            clip: true
            model: playFromHour.popup.visible ? playFromHour.delegateModel : null
            currentIndex: playFromHour.highlightedIndex
        }
    }
}

但我在每个号码周围都面对着一个很大的不可定制的框架。见附图:

我需要将此帧的大小减小到零,但我只是不知道如何做到这一点。请问有什么想法吗?

我需要解决它,所以我将能够减少组合框的宽度。因为现在宽度< 40个像素,那些白色框架/边框在弹出窗口内占据整个空间。

所以没有文字的地方。

1 个答案:

答案 0 :(得分:0)

您必须确定ListView占用父级的相同空间,因为使用了anchors.fill : parent

contentItem: ListView {
    clip: true
    model: playFromHour.popup.visible ? playFromHour.delegateModel : null
    currentIndex: playFromHour.highlightedIndex
    anchors.fill: parent
}