问题:

有时候会遇到这样的情况,在QTableWidget中我们需要嵌入一个QpushButton按钮,但是如何确定是哪个Button按下的呢?

解决:

一般地,一个按钮按下后会连接到一槽函数,那么在槽函数中我们可以这样做:

QPushButton *button = dynamic_cast<QPushButton *>(QObject::sender()); //找到信号发送者
QModelIndex index = ui->tableWidget->indexAt(button->pos());  //定位按钮
QTableWidgetItem *item = ui->tableWidget->item(index.row(), 0);  //得到item

这样就得到了Button所在的位置了,是不是很简单呢?

 

http://www.cnblogs.com/luoxiang/p/5551852.html

相关文章:

  • 2022-12-23
  • 2021-04-30
  • 2021-10-17
  • 2022-01-03
  • 2021-08-24
  • 2021-08-11
  • 2021-06-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案