我有一个简短的问题。我想截取树形视图上的点击事件,根据点击的列有不同的行为。我相信有一个信号可以通过模型指数...但是如何识别列呢?谢谢你的帮助。
发布于 2016-08-02 03:50:06
选中QTreeView中使用的QItemSelectionModel以处理选择,或单击行o列中的事件。将treeview设置为可选,并使用其中一个默认信号。你有3个不同的信号来处理点击事件:
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
void currentColumnChanged(const QModelIndex ¤t, const QModelIndex &previous)
void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)使用自定义槽处理信号,并使用QModelIndex参数获取当前行和索引。示例:
void MainWindow::elementClicked(const QModelIndex& current, const QModelIndex& previous) {
const int row = current.row();
const int column = current.column();
qDebug() << "Clicked at " << row << column;
}https://stackoverflow.com/questions/38689428
复制相似问题