how to use listView enevt
i use a listView
i select one line, is there have any event ?
if selection changed , is it can emit any event ?
how to use it ?
i find i function
This slot is called when the selection is changed. The previous selection (which may be empty), is specified by deselected, and the new selection by selected.
See also setSelection().
but, it's don't work..
my code
Code:
{
qDebug()<<"selection changed !";
}
Re: how to use listView enevt
what do you want to achieve?
Re: how to use listView enevt
you can use QItemSelectionModel which you can get pointer to with
Edit:
Ok I checked and for me that slot:
in my view inherited from QListView is working fine. Is your MusicSettingsWidget derived from any view class (QAbstractItemView, QListView etc)?
Re: how to use listView enevt
I have solved this problem, qt has a clicked signal function that emitted when a mouse button is clicked. The item the mouse was clicked on is specified by index. The signal is only emitted when the index is valid.
Code:
connect(ui
->listView_Group,
SIGNAL(clicked
(const QModelIndex &)),
this,
SLOT(selectionChanged
(const QModelIndex &)));
Code:
void MusicSettingsWidget
::selectionChanged(const QModelIndex & index
) {
if ( index.data().toString() != "all music" ){
musicSettings4a6ConfigFile->beginGroup("GroupList");
musicList << musicSettings4a6ConfigFile
->value
(index.
data().
toString()).
toString().
split(";",
QString::SkipEmptyParts);
musicSettings4a6ConfigFile->endGroup();
mp3ListModel->setStringList(musicList);
ui->listView->setModel(mp3ListModel);
ui->listView->selectAll();
}else{
mp3ListInit();
}
}