怎样让QItemSelectionModel 的currentRowChanged信号的previous参数第一次返回行为0
要让QItemSelectionModel的currentRowChanged信号的previous参数第一次返回行为0,可以在QItemSelectionModel的初始化时设置其selection属性为QItemSelection的第0行。
具体的代码示例如下:
QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
QModelIndex firstIndex = model->index(0, 0); // 获取第0行的索引
QItemSelection firstSelection(firstIndex, firstIndex); // 构造第0行的选择范围
selectionModel->select(firstSelection, QItemSelectionModel::Select); // 设置第0行为选中状态
这样,在currentRowChanged信号的第一次触发时,previous参数就会返回0。
原文地址: https://www.cveoy.top/t/topic/ilJX 著作权归作者所有。请勿转载和采集!