点击 QTableView,触发事件 您所在的位置:网站首页 qtableview双击获取内容 点击 QTableView,触发事件

点击 QTableView,触发事件

2023-09-02 01:53| 来源: 网络整理| 查看: 265

Here is an example of how you can get a table cell's text when clicking on it.

Suppose a QTableView defined in some MyClass class. You need to connect the clicked signal to your own MyClass::onTableClicked() slot, as shown below:

connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTableClicked(const QModelIndex &)));

 

注意:QT的connect只写参数类型,不写参数名。

Slot implementation:

void MyClass::onTableClicked(const QModelIndex &index) { if (index.isValid()) { QString cellText = index.data().toString(); } }

 

You can use also doubleClicked, pressed or other signals depending on your goal.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有