如何将 ItemDelegate 设置为仅应用于 QTreeView 中的父列
How to set ItemDelegate to only apply to parent column in QTreeView
我将QCombobox插入QTreeView的第一列,如下所示。
view->setItemDelegateForColumn(0, new ComboBoxDelegate(view));
第 0 列中的节点有孩子,他们(如果我没记错的话(也是"0"列的一部分。因此,组合框也出现在那里。如何防止组合框出现在子分支中?
我现在拥有的:
>Combobox1
Combobox2
我希望它看起来如何:(其中"文本"取决于组合框的索引(
>Combobox1
Text
以下是创建组合框的一些函数:
ComboBoxDelegate::ComboBoxDelegate(QObject *parent): QItemDelegate(parent){
}
QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const{
QComboBox *editor = new QComboBox(parent);
editor->addItem("Run");
editor->addItem("Run with SM");
editor->addItem("Kinetic Run");
}
return editor;
}
你应该做的是使用QModelIndex &index
参数来获取行,然后说出类似的话:
if (!index.parent().isValid()) {
//draw combobox
}
else {
//don't draw
}
相关文章:
- 使用 fopen 打开 .pak 文件并使该文件应用于 const 无符号字符* (C++)
- 使用 std::应用于 std::bind
- 如何将Affine3d应用于Vector3d
- 运算符 += 应用于 std::valarray<int*>
- 函数可以应用于 std::optional,并返回一个可选值吗?
- 为什么带有类型参数的运算符 () 可以应用于 result_of 上下文中的类型?
- 当正斜杠运算符应用于C++中的字符串类型时,它会做什么
- 将MFPKEY_ASFMEDIASINK_AUTOADJUST_BITRATE应用于IMFSinkWriter
- (C++)(Visual Studio) 将高斯模糊滤镜应用于 RGB 中的灰度图像
- 在运行时将更改的环境变量应用于 QApplication
- Strcmp 类行为应用于C++中的对象列表
- 如何将 ItemDelegate 设置为仅应用于 QTreeView 中的父列
- 什么是应用于C 和CMAKE的定义
- 将对象方法从向量应用于C 的第二个向量中的对象
- STL:将功能应用于Adchacent_difference的结果,而无需额外的容器
- WXWIDGETS应用于WXStaticBitMap时,屏幕截图将大部分图像留为空白
- 如何将垂直纹理应用于QT Surface3D
- 如何将[[nodiscard]]属性应用于lambda
- 奇怪的语法构造 - 应用于 typedef 的运算符 () 使用 VS2015 成功编译
- 将 QPropertyAnimation 应用于 QRect