QTable查看如何确定是否选择了“行”
QTableView how to find out if Row is selected?
我有一个QTableview,它设置了一个QTableModel。
可以修改此视图,例如移动和删除行/列等。
我有一个函数将表格模型导出为 excel/csv,它采用 QTableModel,但是如果模型被修改,该模型不会反映视图,所以我有一个函数,可以根据 QTableViews 当前布局创建新的表格模型。
但是,我现在希望能够选择几行并仅导出所选行,因此本质上我只需要基于视图中的选定行而不是所有行创建一个模型。
下面显示了我当前的循环,
// Loop over the view's data and add it to the map for the model
for(int i = 0; i < rowIndexs.size(); ++i)
{
// Loop over visible headers only as we are matching the view not the model
for(int j = 0; j < headersIndexs.size(); ++j)
{
// Column is the logical index of the visual index of the current column, this values is used as which column to look at in the model to get the cell data
int column = this->horizontalHeader()->logicalIndex(headersIndexs.at(j));
int row = this->verticalHeader()->logicalIndex(rowIndexs.at(i));
/// add to some data container thats not important for this question....
}
所以现在只让选定的行添加到我的容器中,我只想检查这行是否被选中,例如。
if(this->VerticalHeader()->at(row).isSelected)
{
// Add it to the container
}
else
{
// Ignore it and just go to the next one
}
QTableView 行上是否存在这样的isSelected
函数? 如果是这样,那是什么?
干杯
QItemSelectionModel *select = tableview->selectionModel();
QItemSelctionModel 具有以下调用来检索 QModelIndex 的列表。
QModelIndexList selectedColumns ( int row = 0 ) const
QModelIndexList selectedIndexes () const
QModelIndexList selectedRows ( int column = 0 ) const
从 QModelIndex 到 col 和 row
int row = modelindex.row()
int col = modelindex.col()
从(行,列)到QModelIndex
QModelIndex idx = QTableModel->index(row, col)
相关文章:
- 表达式 SFINAE:如何根据类型是否包含具有一个或多个参数的函数来选择模板版本
- 选择排序时交换函数调用的数量和完成的交换次数是否相同?
- 是否可以在运行时调用用于选择要调用的用户定义文本的逻辑?
- 是否可以在C++中使用三元运算符在 if 语句中选择比较运算符?
- 对于这个问题,是否有更好的数据结构和算法选择
- cv::cuda::setTo()是否有其他选择
- 当通过常量和不是字符串的最佳选择时,是否有任何情况?
- 我的选择排序代码是否存在导致它跳过数组中的元素的问题?
- 谷神星求解器:残差函子使用的可变对象是否良好实践?还有什么其他选择
- CMake FindPackage(PythonLibs):CMake 是否优先选择动态库或静态库?
- 如何判断 QFileDialog 是否已关闭而不选择文件
- 在 C++14 中,是否有一种优雅的解决方案可以在可变参数模板中选择可调用和不可调用的类型
- 是否可以在被阻止时重置选择的超时?
- C++17 : "带初始值设定项的选择语句"是否损坏?
- 是否可以从定义的数字集中选择随机数
- 我是否应该使用功能指针在构造函数中选择实现
- 是否在重载选择期间未考虑默认参数的转换
- 是否可以在运行时选择可以访问类的私有成员的函数
- QTable查看如何确定是否选择了“行”
- 如果我想编写一个C程序,是否在CodeBlocks中选择C或C 文件真的很重要