How to emit signal, when user changes row with keyboard arrows in tableView?

StackOverflow https://stackoverflow.com/questions/20441814

  •  30-08-2022
  •  | 
  •  

Вопрос

I have two tableViews, in one I load album names, in the other I want to load tracks from selected album.

Problem is simple: I can't use signals such as activated, mouse clicked, etc. I want to change stuff in the tracks tableView simply by the highlighting row in the album names tableView.

Summary: emit signal when user changes row and find out on which row he is now.

Это было полезно?

Решение

See the Handling selection of items section in the Qt Model/Views documentation.

In essence, what you need to use is your QTableView's selection model which has signals for when the selection changes in the table. You access the view's selection model via it's selectionModel() member function.

Другие советы

Ok,so i have solved this problem like this:

First, you must obtain QItemSelectionModel !after! the table was filled:

QItemSelectionModel *select = ui->tableView->selectionModel();

Then connect SIGNAL "selectionChanged" with you own SLOT function:

connect(select, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(change_table()));

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top