如何使“QTableWidget”项目仅在单击第一列时才被选中
How to make `QTableWidget` items to be selected only when first column is clicked
我想要具有下一行为的QTableWidget
:
-
它应该是可选择的行,并且只能选择一行,我可以用
setSelectionBehavior(QAbstractItemView::SelectRows);
来做setSelectionMode(QAbstractItemView::SingleSelection)
-
现在,我希望只有当用户单击第一列中的项目时才选择行。当用户点击其他列中的项目时,选择不应该改变。我该怎么做?
您需要将QTableWidget
子类化才能以这种方式重新实现mousePressEvent
#include <QMouseEvent>
#include <QTableWidget>
class Table : public QTableWidget {
virtual void mousePressEvent(QMouseEvent * event) {
//the selectable column index
const int SELECTABLE_COLUMN = 0;
//retrieve the cell at pos
QModelIndex i = indexAt(event->pos());
//check if the item is in the desired column
if ( i.column() == SELECTABLE_COLUMN ) {
//behave as normal
QTableView::mousePressEvent(event);
}
//else nothing (ignore click event)
}
};
票据
- 与
QTableView
相同
相关文章:
- 查找矩阵C++中每一列和每一行的最小和最大元素
- 如何在C++中获取二维数组中最少的一列数?
- 如何允许用户选择何时停止三列中的每一列的旋转
- 从我的2d数组中的一列返回的字符串值被压缩为一个字符串(在Mac os上打开Windows txt文件)
- 在犰狳立方体中添加一列 1 的有效方法
- 在二维向量的每一列中查找最大值
- 只有一列适合其内容大小,而另一列则拉伸
- 如何将单独的数组分组在一起(类似于按一列对表进行排序)
- C++ 最后一列中的直方图错误
- 添加两个矩阵会打印一列垃圾数据 c++
- C 特征:通过参考将矩阵的一列传递到函数中
- 仅制作一列qtreewidget可编辑//故障排除
- 在 QTableView 中仅对一列进行排序,而不对其他列进行排序.独立列
- 按列对CSV文件进行排序,并与C 中的另一列进行比较
- 隔离C 中向量的一列
- 读取数据文件并将每一列分配给各个数组
- 按一列对二维数组进行气泡排序
- 可能的话,将QComboBox映射到MySQL表的一列
- 数据排序依据是哪一列,QTableWidget
- 找出QTableWidget中选择了哪一列