The problem is likely that you never let the table widget do anything with the mouse press event when it is a left press. The events don't magically get passed up the line unless you call QTableWidget:: mousePressEvent() in addition to whatever you do with it.
You are also calling QWidget's mousePressEvent() handler instead of the superclass of your own Table class (presumably QTableWidget) which bypasses the QTableWidget's handling of any other mousePressEvent. So it is no wonder your table widget isn't working properly - you've completely prevented it from seeing any mouse press events at all.
So in the code you posted last, there's no correct current row or current column, because you haven't let the table widget see the mouse press event before your code swallows it and eats it.
Try this instead:
{
if(event->button( ) == Qt::LeftButton)
{
cout << "(" << this->currentRow( ) << ", " << this->currentColumn( ) << ")" << endl;
}
}
void Table::mousePressEvent(QMouseEvent *event)
{
QTableWidget::mousePressEvent( event );
if(event->button( ) == Qt::LeftButton)
{
cout << "(" << this->currentRow( ) << ", " << this->currentColumn( ) << ")" << endl;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks