如何在Qt中获取selectionchange事件

Nar*_*uto 7 qt symbian nokia qt4

我有一个继承自的类QWidget,现在在该类中我将创建一个QListView对象并填充要查看的项目.当列表视图中的项目选择发生变化时,我想获得该selectionChange事件.

我怎么能实现这个目标?请简要告诉我.

And*_*y M 10

当您有视图时,您将拥有一个用于选择项目的模型.它叫做a QItemSelectionModel.

例如,使用您的QListView,您可以这样获得selectionModel:

QItemSelectionModel* selectionModel() const;
Run Code Online (Sandbox Code Playgroud)

现在,从该模型中,您将能够连接许多信号:

void currentChanged ( const QModelIndex & current, const QModelIndex & previous )
void currentColumnChanged ( const QModelIndex & current, const QModelIndex & previous )
void currentRowChanged ( const QModelIndex & current, const QModelIndex &    previous )
void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
Run Code Online (Sandbox Code Playgroud)

我想它会对你有所帮助!