【问题标题】:How can I assign the click event handler as I click the row in QT?当我单击 QT 中的行时,如何分配单击事件处理程序?
【发布时间】:2016-01-14 13:35:19
【问题描述】:

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

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

如果我在点击视图上的第 i 行时需要跳转另一个表单,我该如何分配点击事件?

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

【问题讨论】:

  • 另一种形式是什么意思..?你的意思是其他一些小部件。>?你能添加一些代码来显示吗?

标签: qt qtgui qtsql


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    相关资源
    最近更新 更多