Engo
Engo

Reputation: 969

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. How can I do this?

The following function adds 1 row to the QTableWidget:

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], ....)

Upvotes: 1

Views: 667

Answers (1)

Brad
Brad

Reputation: 486

You'll need to connect to the doubleClicked signal which is available in the QAbstractItemView base class:

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.

Upvotes: 1

Related Questions