How to click and doubleclick correctly on a QTableWidget (Qt)?

990 views Asked by At

I have a QTableWidget and I need to call some functions based on the user click on the cell.

I am currently using the following signals and slots:

// cellClicked(int,int)
void MyClass::on_myTableWidget_cellClicked(int row, int column)
{
    qDebug() << "Click";
}

// cellDoubleClicked(int,int)
void MyClass::on_myTableWidget_cellDoubleClicked(int row, int column)
{
    qDebug() << "Double Click";
}

The problem is that the on_myTableWidget_cellClicked is only called when I use the left mouse button. If I use the right mouse button it does not work. And the on_myTableWidget_cellDoubleClicked is called on both left or right mouse buttons.

What I actually want is that the on_myTableWidget_cellClicked be called using both the left or right mouse buttons, and that the on_myTableWidget_cellDoubleClicked be called only when I use the left mouse button.

How can I do that? Just using eventFilter? If yes how can I get the correct row from the QTableWidget?

I am using Qt version 5.3.2.

1

There are 1 answers

0
Michał Walenciak On

When you right click, context menu related signal/event is being launched.

See here for more details.