我有一个设置了QTableModel的QTableview。
该视图可以修改,例如。行/列移动和删除等。
我有一个将表模型导出到带有QTableModel的excel / csv的函数,但是如果模型被修改,该模型不会反映视图,因此我有一个函数可以基于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....
}
Run Code Online (Sandbox Code Playgroud)
所以现在要只使选择的行添加到我的容器中,我想检查一下是否选中了该行。
if(this->VerticalHeader()->at(row).isSelected)
{
// Add it to the container
}
else
{
// Ignore it and just go to the next one
}
Run Code Online (Sandbox Code Playgroud)
isSelectedQTableView行上是否存在这样的功能?如果是这样,那是什么?
干杯
小智 6
QItemSelectionModel *select = tableview->selectionModel();
Run Code Online (Sandbox Code Playgroud)
QItemSelctionModel具有以下调用以检索QModelIndex的列表。
QModelIndexList selectedColumns ( int row = 0 ) const
QModelIndexList selectedIndexes () const
QModelIndexList selectedRows ( int column = 0 ) const
Run Code Online (Sandbox Code Playgroud)
从QModelIndex到col和row
int row = modelindex.row()
int col = modelindex.col()
Run Code Online (Sandbox Code Playgroud)
从(行,列)到QModelIndex
QModelIndex idx = QTableModel->index(row, col)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2791 次 |
| 最近记录: |