如何禁用QTableView的整列选择
How to disable whole column selection of QTableView?
void setSelectionBehavior(QAbstractItemView::SelectionBehBehavior behavior)
此函数接受三个值之一:用于选择项目、用于选择行和选择单元格。
问题:
我需要这样的情况,当单击一个单元格时,它被选中,当单击行索引时,行被选中,但当单击列标题时,整个列没有被选中。据我所知,使用此函数无法完成此操作。
我需要表视图的行为与设置SelectionBehavior::selectItems
时完全相同。
但当用户单击标题时,不应选择该列。
我正在考虑禁用QHeaderView
中的列选择,但找不到如何禁用?
来自我的应用程序:
// get header from QTableView tableView (replace with your widget name)
QHeaderView *header = new QHeaderView(Qt::Horizontal, tableView);
#if QT_VERSION < 0x50000
// Qt 4.8.1
header->setResizeMode(QHeaderView::ResizeToContents);
#else
// Qt 5.2.0
header->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
header->setHighlightSections(false); // this is what you want
setHighlightSections(bool)插槽对Qt 4和Qt 5 有效
编辑:原谅你粗心大意!只有在将SelectRows或SelectItems与SingleSelection一起使用时,此选项才有效。您可以在源qheaderview.cpp
和qtableview.cpp
、槽voidQHeaderView::mousePressEvent(QMouseEvent *e);
和voidQTableViewPrivate::selectColumn(int column, bool anchor);
中找到证明
对于SelectItems可以使用此插槽:
header->setClickable(false);
相关文章:
- QTreeView幻灯片多选后无法使用单击选择
- 如何允许用户选择何时停止三列中的每一列的旋转
- extensor:选择具有特定列值的行
- 特征 3 根据列条件选择出行
- 从两列中选择一个数字并进行计算
- 如何在垫子中选择一些特定的列?
- 当列中的属性与eigen,c 中的给定条件匹配时,仅选择这些行froom a矩阵
- 如何将所选行的第一列值绑定到变量并在 QT 的 SQL 命令中使用它?
- 如何选择 QTableView 的特定整个列
- CDao记录集从列中选择全部
- 从 QT 复选框到 Postgresql 选择星期几
- C++具有无限可选参数和不同输入变量选择的函数
- 如何在单选按钮分组框中获取用户的选择以进行进一步处理
- C++ 如何通过可选的typedef,使用SFINAE或其他方式选择类
- 高效读取带有可选列的 CSV 文件
- Qt 中的多重选择和非多重选择复选框
- mysql C++从所有列中选择所有行
- C++中2D阵列的用户选择列
- 如何在次线性时间内从行主数组中选择列
- sqlite:如何获取所选列的列id