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