【问题标题】:how to select multiple columns in QTable如何在QTable中选择多个列
【发布时间】:2011-07-25 11:53:04
【问题描述】:

我在 c++/ubuntu 中工作。我创建了一个 QTable :

  1 | 2
 -------
aaaa|bbbb
cccc|dddd
....|....

我想问我如何选择整个第2行:cccc |dddd。

我做到了:

QModelIndexList indexes = ui->tableView->selectionModel()->selection().indexes();

    for (int i = 0; i < indexes.count(); ++i)

    {
        QModelIndex index = indexes.at(i);

        if (index.isValid())
        {

          QString s=index.data(Qt::DisplayRole).toString();
          QMessageBox noc;
                  noc.setText(s);
                  noc.exec();
        }


    }

但我只看到 tje cccc 元素被选中。

欣赏。非常感谢!

【问题讨论】:

  • QTable 已弃用 Qt2|3 类。你真正使用哪个类?请澄清你的问题。您想通过单击以编程方式或手动方式选择一行吗?您发布的代码仅显示选择,而不是尝试选择某些内容。

标签: c++ qt ubuntu qt-creator qt-designer


【解决方案1】:

如果您使用的是Q3Table,则有an enum for handling selections,它是使用this function 设置的。

如果您使用QTableView(推荐),则可以使用a similar enumfunction 进行设置。

我希望这会有所帮助。正如 Raiv 在评论中所说,如果您澄清您的问题,我们可以为您提供更多帮助。

【讨论】:

    【解决方案2】:

    尝试使用QTableView::selectedIndexes。该函数用于获取选中的项目。

    【讨论】:

      猜你喜欢
      • 2018-03-26
      • 1970-01-01
      • 2022-11-11
      • 2018-05-15
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多