如何在单击 QT 中的行时分配单击事件处理程序



我知道如何绑定QSqlTableModel和QTableView来显示数据库中特定表中的所有数据。在这里,这是我的代码。

QSqlTableModel model;
QTableView *view1 = createView(&model, QObject::tr("Table Model (View 1)"));
view1->setSelectionBehavior(QAbstractItemView::SelectRows);

如果我需要在单击视图上的第三行时跳转其他窗体,如何分配单击事件?

例如,如果我单击第 3 行,我将跳转到用户窗体以显示第 3 行用户信息。

通过调用 QTableView::selectionModel() 从中获取 QItemSelectionModel。连接到信号 QSelectionModel::selectionChanged(QItemSelection const&, QItemSelection const&)。在您的插槽中,您可以检查选择的更改,以确定单击了什么。

相关内容

最新更新