获取tablewidget中添加pushbutton指针

wjian20 2014-08-03 01:07:20
当鼠标点击tablewidget中某个单元格的pushbutton时,如何获得pushbutton指针和所在单元格的行列号?
void QTableWidget::itemClicked(QTableWidgetItem * item) [signal]
void QTableWidget::cellClicked(int row, int column) [signal]
上面信号都不能实现,还有哪位高手有其他的方法

...全文
2081 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
不回头的倔强 2016-12-09
  • 打赏
  • 举报
回复
引用 15 楼 wuchalilun 的回复:
楼主一得到答案就再也不会来了,好歹把答案贴出来啊。
就是啊,好歹结一下帖子
不回头的倔强 2016-12-09
  • 打赏
  • 举报
回复
你好,怎么解决的,请帮助啊
Ray_Chang_988 2016-08-02
  • 打赏
  • 举报
回复
楼主一得到答案就再也不会来了,好歹把答案贴出来啊。
qq_14841287 2015-08-25
  • 打赏
  • 举报
回复
你最后是怎么弄的
oQuWeiCunZhen 2015-08-10
  • 打赏
  • 举报
回复
你好,我想问下你是怎么解决这个问题的,我也同样遇到了这个问题
caoanqi 2015-07-06
  • 打赏
  • 举报
回复
QPushButton* button = new QPushButton(ui->tableWidget); QPoint post = sender->pos(); QModelIndex index = ui->tableWidget->indexAt(post);
zhanglaobi 2015-06-09
  • 打赏
  • 举报
回复
请问是到底是怎么解决的啊
792199369 2015-05-24
  • 打赏
  • 举报
回复
引用 8 楼 wjian20 的回复:
谢谢各位,问题解决了。
能问一下怎么解决的吗?
z554962483 2014-10-20
  • 打赏
  • 举报
回复
请问您是怎么解决的,能否告知一下,我也遇到这个问题了。。。。谢谢
wjian20 2014-08-06
  • 打赏
  • 举报
回复
谢谢各位,问题解决了。
Inhibitory 2014-08-06
  • 打赏
  • 举报
回复
QWidget::pos() QPoint QWidget::mapToGlobal(const QPoint & pos) const
wjian20 2014-08-04
  • 打赏
  • 举报
回复
引用 3 楼 WeiXiao_365 的回复:
这个点击有pushbutton的cell不能识别cell的行列,是没有触发cellClicked而只是触发了pushbutton的clicked。 但是如果你的表格如果是用setCellWidget把这个pushButton添加去,应该点击pushButton是会触发表格的cellClicked信号的, 你是不是直接放上去pushButton,而不是用的setCellWidget加进去的呢?
兄弟我的确使用setCellWidget把按键添加上去的啊。 Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::Form) { ui->setupUi(this); ui->tableWidget->setCellWidget(0,0,new QPushButton()); ui->tableWidget->setCellWidget(0,1,new QPushButton()); ui->tableWidget->setCellWidget(0,2,new QPushButton()); connect(ui->tableWidget, SIGNAL(cellClicked(int,int)),\ this, SLOT(on_cellClicked(int,int))); } Form::~Form() { delete ui; } void Form::on_cellClicked(int row, int column) { ui->rowLine->setText(QString::number(row)); ui->columnLine->setText(QString::number(column)); }
wjian20 2014-08-04
  • 打赏
  • 举报
回复
引用 5 楼 Inhibitory 的回复:
可以这么试试: 1. 得到pushbutton的坐标 2. QTableView::indexAt(); QModelIndex QTableView::indexAt(const QPoint & pos) const [virtual] Reimplemented from QAbstractItemView::indexAt(). Returns the index position of the model item corresponding to the table item at position pos in contents coordinates.
兄弟如何获取pushbutton的坐标呢? 使用鼠标事件只能获得tablewidget坐标,但是无法获得pushbutton的坐标
WeiXiao_365 2014-08-04
  • 打赏
  • 举报
回复
这个点击有pushbutton的cell不能识别cell的行列,是没有触发cellClicked而只是触发了pushbutton的clicked。 但是如果你的表格如果是用setCellWidget把这个pushButton添加去,应该点击pushButton是会触发表格的cellClicked信号的, 你是不是直接放上去pushButton,而不是用的setCellWidget加进去的呢?
Inhibitory 2014-08-04
  • 打赏
  • 举报
回复
可以这么试试: 1. 得到pushbutton的坐标 2. QTableView::indexAt(); QModelIndex QTableView::indexAt(const QPoint & pos) const [virtual] Reimplemented from QAbstractItemView::indexAt(). Returns the index position of the model item corresponding to the table item at position pos in contents coordinates.
wjian20 2014-08-03
  • 打赏
  • 举报
回复
引用 1 楼 LazyDreamHunter 的回复:
是这样的,单元格中的控件可以通过cellWidget(row, col) 来获得,你可以通过cellWidget信号来得到单击的行和列,再通过cellWidget来获得对应行和列的控件。
兄弟你说的信号应该是是cellClicked(int row, int column) 吧,这个点击没有pushbutton的cell有用,点击有pushbutton的cell根本不能识别cell的行列。
RabinSong 2014-08-03
  • 打赏
  • 举报
回复
是这样的,单元格中的控件可以通过cellWidget(row, col) 来获得,你可以通过cellWidget信号来得到单击的行和列,再通过cellWidget来获得对应行和列的控件。

16,216

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧