tblInventory->indexAt(QPoint(0,2)).d-6ren">
gpt4 book ai didi

c++ - Qt/C++ : Getting the data at a certain cell in a QTableView

转载 作者:IT老高 更新时间:2023-10-28 22:17:20 25 4
gpt4 key购买 nike

我正在尝试获取 QTableView 中某个单元格的文本。例如:

QString codestring = "*" + ui->tblInventory->indexAt(QPoint(0,2)).data().toString() + "*";

这应该会在我的 QTableView 中的第 0 列第 2 行的单元格中获取文本。问题是,这不是它在做什么!无论我将参数传递到 indexAt() 中的 QPoint() 中,我都会在单元格 0,0 处获得文本。我不知道这是为什么……有什么帮助吗?谢谢!

[编辑]
我也试过这个:

QString codestring = "*" + ui->tblInventory->model()->data(ui->tblInventory->indexAt(QPoint(0,2))).toString() + "*";

[编辑 2]试图找出发生了什么,我输入了这行代码:

qDebug()<< ui->tblInventory->indexAt(QPoint(2,2)).row() << " and " <<  ui->tblInventory->indexAt(QPoint(2,2)).column();

它应该在单元格 2,2 处获取 QModelIndex 并输出其行和列,当然应该是 2 和 2。但是,我得到了 0 和 0!所以看起来这可能是 QTableView::indexAt() 的问题,无论是我的用法还是某种错误。有人能解释一下吗?

最佳答案

解决方法:

ui->tblInventory->model()->data(ui->tblInventory->model()->index(0,2)).toString()

不太清楚为什么上述方法不起作用,但确实如此。感谢您的帮助。

关于c++ - Qt/C++ : Getting the data at a certain cell in a QTableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4236942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com