我想在双击上添加''事件到我的QTableWidget中的每一行。我怎样才能做到这一点?
以下函数向QTableWidget添加1行:
void ViewController::addReceivedFileToTable(QString sopInstanceUID, QString sopClassUID, QString fileName)
{
m_mainWindow.getReceivedFilesTableWidget()->insertRow(0);
m_mainWindow.getReceivedFilesTableWidget()->setItem(0,0,new QTableWidgetItem(sopInstanceUID));
m_mainWindow.getReceivedFilesTableWidget()->setItem(0,1,new QTableWidgetItem(sopClassUID));
m_mainWindow.getReceivedFilesTableWidget()->setItem(0,2,new QTableWidgetItem(fileName));
}
我需要类似的东西:
connect(m_mainWindow.getReceivedFilesTableWidget()->[getRow]->[onDoubleClicked], ....)
答案 0 :(得分:1)
您需要连接到QAbstractItemView基类中提供的doubleClicked信号:
connect(m_mainWindow.getReceivedFilesTableWidget(), SIGNAL(doubleClicked(QModelIndex const&)), this, SLOT(onTableItemDoubleClicked(QModelIndex const&)));
onTableItemDoubleClicked的实现必须使用QTableWidget :: itemFromIndex在QModelIndex和QTreeWidgetItem之间进行转换。