Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...