【发布时间】:2014-03-09 09:24:12
【问题描述】:
我有一个设置了 QTableModel 的 QTableview。
可以修改此视图,例如。行/列移动和删除等。
我有一个将表格模型导出到 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 Rows 上是否存在这样的isSelected 函数?如果是的话是什么??
干杯
【问题讨论】:
-
这似乎与您的问题stackoverflow.com/q/5927499/942596 相似
-
不是我的问题,我的欢呼我看看
-
这实际上也没有回答我的问题,我的描述可能应该更清楚。我已经根据
this->verticalHeader()->isSectionHidden(i)是否隐藏了列和行,所以我不能真正使用SelectedIndexs()函数,这就是为什么我问特定行是否有isSelected函数... -
对,有这样的功能:
QItemSelectionModel::isSelected (const QModelIndex &index) -
干杯,这似乎正是我需要的,但我没有行和列的 QModelIndes 位置,我只有行和列整数值??
标签: c++ qt qtableview