【发布时间】:2011-03-30 07:04:25
【问题描述】:
我有一个继承 QTableView 的简单类,我想要以下行为:当用户选择几个单元格时,我希望将选择的第一个单元格设置为当前索引。
例如,如果我从 (0, 0) 到 (2, 2) 选择,当我开始输入时,文本将显示在 (0, 0),而不是 (2, 2),这似乎是默认值.
我已尝试使用以下内容覆盖 setSelection 函数:
void SampleTable::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
{
if((command & QItemSelectionModel::Current) != 0)
{
QModelIndex curr = indexAt(rect.topLeft());
selectionModel()->select(curr, QItemSelectionModel::Current);
command ^= QItemSelectionModel::Current;
}
QTableView::setSelection(rect, command);
}
但无济于事。这似乎与鼠标事件有关,但我在源代码中无法完全定位问题,我希望无论如何有一个更简单的方法。
【问题讨论】:
标签: c++ qt indexing selection qtableview