Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在QTreeView(Qt,QML)中设置各种行高?_C++_Qt_Treeview_Qml - Fatal编程技术网

C++ 如何在QTreeView(Qt,QML)中设置各种行高?

C++ 如何在QTreeView(Qt,QML)中设置各种行高?,c++,qt,treeview,qml,C++,Qt,Treeview,Qml,在我的QML中,我有一个树状视图: TreeView { ... model: mProductions.getModel() TableViewColumn { role: "name" title: "Name" width: root.width/4

在我的QML中,我有一个树状视图:

TreeView {
                ...

                model: mProductions.getModel()

                TableViewColumn {
                    role: "name"
                    title: "Name"
                    width: root.width/4
                }

                TableViewColumn {
                    role: "image"
                    title: "Image"
                    width: root.width/4
                }
}
我需要有更高的行高度,以防项目有一个图像。 因此,我尝试在我的数据方法中为一个项使用Qt::SizeHintRole。但QML不请求此角色

QVariant Productions::TreeItem::data(int role) const {
    switch(role) {
    case NameRole:
        return QVariant(this->name);
    ...
    case Qt::SizeHintRole:
        return QSize(..., ...);
    ...
    default:
        return QVariant();
    }
}

那么我如何强制QML请求这个角色呢?或者是否有其他方法设置不同的行高度?QML中的rowDelegate对我不起作用。

对我来说,使用
rowDelegate:Rectangle{height:25}
更改行的高度。你看过这个定义角色了吗?QML不像QtWidgets那样使用角色。您可以手动查询SizeIntrole,但因此必须为Qt::SizeIntrole指定角色名。然后你可以像其他角色一样查询它。谢谢。我没有找到任何方法从
rowDelegate
获取有关特定项目类型的任何信息,因此我只能为所有项目设置高度。我尝试了不同的角色技巧,但只是遇到了一些奇怪的行为,没有任何有用的结果。你没有其他方法知道你的元素是否包含图像吗?我可以在我的项目模型类中提供任何方法,或者使用角色模型来提供此信息。问题是我无法从
rowDelegate
访问我的模型(确切地说是元素的索引)。