linux qt tableview控制,qt:访问qTableView中的单元格

我想你的桌子是这样的:

+--------+--------+---------+

|Location|Latitude|Longitude|

+--------+--------+---------+

| A | 11'.22"| 11'.22" |

+--------+--------+---------+

从上面的代码可以看出,您希望用户一次选择一整行。

如果是这样,我建议您在

QTableView

:

ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);

ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);

然后我会

connect()

selectionChanged

选择模型信号:

connect(ui->tableView, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &),

this, SLOT(onSelectionChanged(const QItemSelection &))));

下面是插槽的实现:

void MainWindow::onSelectionChanged(const QItemSelection & selected) {

// Due to selection mode and behavior settings

// we can rely on the following:

// 1. Signal is emited only on selection of a row, not its reset

// 2. It is emited for the whole selected row

// 3. Model selection is always valid and non-empty

// 4. Row indexes of all items in selection match

int rowIndex = selected.indexes().at(0).row();

double latitude = model->index(rowIndex, 1).date().toDouble();

double longitude = model->index(rowIndex, 2).data().toDouble();

// Do whatever you want with the values obtained above

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值