qt - 表格 View 中的组合框

标签 qt qml qtquick2

我正在 QML 表格 View 中组合一个 ComboBox,如下所示:

TableView {
    id: reviewTable
    frameVisible: false
    sortIndicatorVisible: true
    width: parent.width; height: parent.height
    anchors.centerIn: parent

    TableViewColumn {
        resizable: true
        role: "SeriesDescription"
        title: "Series Description"
        width: 350
    }

    TableViewColumn {
        resizable: false
        role: "TimePoints"
        title: "Time Points"
        width: 100
    }

    TableViewColumn {
        role: "ImageType"
        title: "Image Type"
        width: 100
        delegate: Rectangle {
            anchors.fill: parent
            //anchors.verticalCenter: parent.verticalCenter
            ComboBox {
                model: ListModel {
                    ListElement {  text: "Veggies" }
                    ListElement {  text: "Fruits" }
                    ListElement {  text: "Cars"  }
                }
            }
        }
    }
}

但是,这会以一种奇怪的方式呈现组合框,其中边界看起来有点被切断。请参阅随附的屏幕截图。有谁知道如何解决这个问题?

enter image description here

最佳答案

这不是完美的解决方案,但无论如何......您可以通过设置 rowDelegate 来更改行高,例如:

rowDelegate: Item {
            height: 30
}

因此拉伸(stretch)组合框以填充所有空间:

TableViewColumn {
        role: "ImageType"
        ...
        delegate: Rectangle {
            ComboBox {
                anchors.fill: parent
                anchors.margins: 2
                model: ListModel {
                    ...
                }
            }
        }
    }

关于qt - 表格 View 中的组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40719532/

相关文章:

c++ - 通用第一个参数 C++ 函数

c++ - QML FileDialog 从 C++ 代码设置标题

c++ - Windows 中的 Qt Creator - 我如何知道正在使用哪个编译器?

在 QVector 中使用指针和非指针参数的 C++ 模板

c++ - 将 txt 文件读入 QStringList

qt - QML:原始模型中的动态 View 重新排序

android - 如何在 Android 上从 Qt5.2 Quick 2 项目访问陀螺仪?

qml - 为什么使用 QAbstractTableModel 而不是 QAbstractListModel?

c++ - QtQuick 双屏支持

qt - 在 qml Qt 中设置样式