Qt/C++ QTableWidget: Doing something when a header is doubleclicked

牧云@^-^@ 提交于 2019-12-01 05:47:05

问题


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)


回答1:


http://doc.qt.nokia.com/latest/qheaderview.html#sectionDoubleClicked

You can get the QHeaderView via QTableWidget::horizontalHeader() or QTableWidget::verticalHeader().



来源:https://stackoverflow.com/questions/4128539/qt-c-qtablewidget-doing-something-when-a-header-is-doubleclicked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!