如何以编程方式选择QTableView中的下一行 [英] How to select next row in QTableView programmatically
问题描述
我有QTableView子类,im标记和保存其状态为:
i have QTableView subclass that im marking and saving its state with this :
connect(this,
SIGNAL(clicked(const QModelIndex &)),
this,
SLOT(clickedRowHandler(const QModelIndex &))
);
void PlayListPlayerView::clickedRowHandler(const QModelIndex & index)
{
int iSelectedRow = index.row();
QString link = index.model()->index(index.row(),0, index.parent()).data(Qt::UserRole).toString();
emit UpdateApp(1,link );
}
现在我喜欢以编程方式将选择移动到下一行用鼠标的行)
和调用clickedRowHandler(...)如何shell我这样做?
感谢
now i like programmatically to move the selection to the next row (not by pressing the row with the mouse) and invoking clickedRowHandler(...) how shell i do that ? Thanks
推荐答案
您已经拥有当前的行索引,所以使用类似下面的方法来获取modelindex
You already have the current row index, so use something like the following to get the modelindex for the next row
QModelIndex next_index = table->model()->index(row + 1, 0);
然后,您可以使用
table->setCurrentIndex(next_index);
很明显,你需要确保你没有超过表的末尾,可能有一些额外的步骤,以确保整个行被选中,但应该让你更接近。
Obviously you'll need to make sure you're not running past the end of the table, and there's probably some extra steps to make sure the entire row is selected, but that should get you closer.
这篇关于如何以编程方式选择QTableView中的下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!