Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

c++ - How to select next row in QTableView programmatically

I have QTableView subclass that I am 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 );
}

now i like programmatically to move the selection to the next row (not by pressing the row with the mouse) and invoking clickedRowHandler(...) how shall i do that ? Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

Then you can set that modelindex as the current one using

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...