Qt 点击 QTableView,触发事件


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:

1 void MyClass::onTableClicked(const QModelIndex &index) 2 { 3     if (index.isValid()) 4  { 5         QString cellText = index.data().toString(); 6  } 7 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM