Catch button clicked in a Qtablewidget cell

Question:

I am adding 2 buttons in each cell of my Qtablewidget and I want to perform a specific action for each clicked button. The problem is that I am only able to detect the click on the entire cell but not which clicked button. I am using pyqt4 and Python 3.5

Could you please help me to solve this problem?
Thanks

Asked By: Ikram Romdhani

||

Answers:

I guess you are already watching the QTableWidget::cellClicked(int row, int column)-signal with some slot, or?
You could try to acquire the sender, which of both buttons it was, by something similar to this:

#include <QtCore/QMetaObject>
#include <QtCore/QMetaMethod>

{
    QMetaMethod const metaMethod = sender()->metaObject()->method(senderSignalIndex());
    qDebug() << "invoking caller: name and signature:" << metaMethod.name() << "|" << metaMethod.methodSignature();
}

(please adapt yourself to PyQt).


Or: you add connections for each of the buttons for each cell at the creation.

Answered By: Marcel Petrick
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.