QTableWidget cellClicked and cellDoubleClicked
I have a QTableWidget with row selection, and i'm trying to treat 3 signals:
•cellClicked
•cellDoubleClicked
•customContextMenuRequested
Things seem to be fine in code: i had in mind the connect syntax, type params are correct and match, etc; and to be more specific, i "know" that the code is correct because i have the following situation:
•if i connect the 3 signals to their respective slots, only the single click and the context menú work.
•if i connect just one signal each time i compile the code and i run the program, that signal is working well (for the 3 of them).
•if i connect the single click signal and the context menu, commenting the connect macro for the double click, they work well. Same for double click and context menu.
BUT if i connect the single click and the double click, the double click is not being treated by my custom slot.
Just to clarify, each signal has a different slot, and as i meantioned above, they work well if i just connect one of them and comment the other 2 in code.
So my question is: is there any bug with the cellClicked and cellDoubleClick working simultaneously? do i have to set some flag, attribute or whatever that belongs to the QTableWidget?
I'm running out of ideas, thanks for the help!
And also, maybe the code should help:
table and slots declaration:
Code:
public slots:
void tableChange(int row, int column);
void tableChangeDbl(int row, int column);
void PopupMenuTableShow
(const QPoint &);
the connects:
Code:
connect(table, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(tableChangeDbl(int, int)));
connect(table, SIGNAL(cellClicked(int, int)), this, SLOT(tableChange(int, int)));
connect(table,
SIGNAL(customContextMenuRequested
(const QPoint &)),
this,
SLOT(PopupMenuTableShow
(const QPoint &)));
1 Attachment(s)
Re: QTableWidget cellClicked and cellDoubleClicked
Here is an example code where all three signals are emitted.
Make a note of this
1. When mouse left cliecked -> cellClicked() is emitted.
2. When mouse left double clicked -> cellClicked() and cellDoubleClicked() is emitted.
3. When mouse right clicked -> cellClicked() and customContextMenuRequested() is emitted.
Attachment 9023
Code:
#include <QtGui>
#include <QApplication>
{
Q_OBJECT
public:
{
connect(table, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(tableChangeDbl(int, int)));
connect(table, SIGNAL(cellClicked(int, int)), this, SLOT(tableChange(int, int)));
table->setContextMenuPolicy(Qt::CustomContextMenu);
connect(table,
SIGNAL(customContextMenuRequested
(const QPoint &)),
this,
SLOT(PopupMenuTableShow
(const QPoint &)));
show();
}
public slots:
void tableChange(int row, int column)
{
append
(QString("Clicked %1, %2").
arg(row
).
arg(column
));
}
void tableChangeDbl(int row, int column)
{
append
(QString("Double Clicked %1, %2").
arg(row
).
arg(column
));
}
void PopupMenuTableShow
(const QPoint & point
) {
append
(QString("Menu %1, %2").
arg(point.
x()).
arg(point.
y()));
}
};
int main(int argc, char **argv)
{
Widget widget(&tableWidget);
tableWidget.setRowCount(10);
tableWidget.setColumnCount(2);
for(int r = 0 ; r < tableWidget.rowCount(); r++)
for(int c = 0 ; c < tableWidget.columnCount(); c++)
tableWidget.setWindowTitle("QTableWidget");
widget.setWindowTitle("Widget");
tableWidget.show();
widget.show();
return app.exec();
}
#include "main.moc"