Qt/C++ QTableWidget:双击标题时执行某些操作
我的表单中有一个 QTableWidget,我想在用户双击行或列的标题时执行某些操作。我正在使用以下连接语句:
connect(ui->tblResults->horizontalHeader(),SIGNAL(doubleClicked(QModelIndex)),this,SLOT(tableDoubleClicked(QModelIndex)));
其中 this
是窗口类,ui->tblResults 是窗口窗体上的 QTableWidget。当我尝试双击标题时,没有任何反应。我要连接的插槽是:
void wndSearch::tableDoubleClicked(QModelIndex tmp){
QMessageBox::information(0,"DERP!","TEST");
}
非常简单,只需测试该插槽是否被调用。我从来没有收到过这个消息框。我在 connect() 调用上没有收到任何运行时错误。
我使用了错误的信号吗?还有什么问题吗?如果您需要更多信息,请告诉我,感谢您的帮助!
[编辑] freenode 上#qt 中的某人帮助了我。我正在寻找的信号是sectionDoubleClicked(int)
I have a QTableWidget in my form and I want to do something when a user doubleclicks on the header of a row or column. I am using the following connect statement:
connect(ui->tblResults->horizontalHeader(),SIGNAL(doubleClicked(QModelIndex)),this,SLOT(tableDoubleClicked(QModelIndex)));
Where this
is the window class and ui->tblResults is the QTableWidget on the window's form. When I try doubleclicking the header, nothing happens. The slot I'm connecting to is:
void wndSearch::tableDoubleClicked(QModelIndex tmp){
QMessageBox::information(0,"DERP!","TEST");
}
Very simple, just testing to see if the slot gets called. I never receive this messagebox. I am not getting any runtime error on the connect() call.
Am I using the wrong signal? Is something else wrong? Please let me know if you need anymore information, and thanks for the help!
[edit]
Someone in #qt on freenode helped me out. SIGNAL I was looking for was sectionDoubleClicked(int)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://doc.qt.nokia.com/latest/qheaderview.html#sectionDoubleClicked
您可以通过
QTableWidget::horizontalHeader()
或QTableWidget::verticalHeader()
获取QHeaderView
。http://doc.qt.nokia.com/latest/qheaderview.html#sectionDoubleClicked
You can get the
QHeaderView
viaQTableWidget::horizontalHeader()
orQTableWidget::verticalHeader()
.