【问题标题】:QTableView select single cellQTableView 选择单个单元格
【发布时间】:2015-01-12 10:49:22
【问题描述】:

我有一个带有 QTableView 的 QT5 应用程序,我想创建一个具有 Go-To Cell 功能的操作。

我面临的问题是,根据documentation,只有selectRowselectColumn 方法可用作公共插槽。
此外,我发现了一个 setSelection 方法,即 [virtual protected] ,并且有一个 setSelectionModel 但我无法围绕构建 QItemSelectionModel 来选择单个单元格。

这似乎是一个微不足道的功能,但由于某种原因它不是 QT api 的一部分。

【问题讨论】:

    标签: c++ qt qt5


    【解决方案1】:

    要选择一项,请使用QItemSelectionModel::​select

    selectionModel()->select( index, QItemSelectionModel::ClearAndSelect );
    

    确保为单个选择设置选择行为

    setSelectionMode(QAbstractItemView::SingleSelection);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-25
      • 2018-06-14
      • 1970-01-01
      • 2011-12-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-03
      相关资源
      最近更新 更多