简体   繁体   English

如何在QTableWidget的整个行中添加“双击”事件?

[英]How to add an 'on double clicked' event to an entire row in a QTableWidget?

I want to add an 'on double clicked' event to each row in my QTableWidget. 我想在我的QTableWidget中的每一行中添加一个“双击”事件。 How can I do this? 我怎样才能做到这一点?

The following function adds 1 row to the 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));
}

I need something like: 我需要类似的东西:

connect(m_mainWindow.getReceivedFilesTableWidget()->[getRow]->[onDoubleClicked], ....)

You'll need to connect to the doubleClicked signal which is available in the QAbstractItemView base class: 您需要连接到QAbstractItemView基类中可用的doubleClicked信号:

connect(m_mainWindow.getReceivedFilesTableWidget(), SIGNAL(doubleClicked(QModelIndex const&)), this, SLOT(onTableItemDoubleClicked(QModelIndex const&)));

Your implementation of onTableItemDoubleClicked will have to convert between the QModelIndex and the QTreeWidgetItem using QTableWidget::itemFromIndex. 您的onTableItemDoubleClicked实现必须使用QTableWidget :: itemFromIndex在QModelIndex和QTreeWidgetItem之间进行转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM