Sorry, i didn't understand! All code examples i saw look alike my code. How can i do that?If that is your actual code then you are forgetting to call the base class implementation of mousePressEvent().
Here, my "guide".
If you are relying on that as your "guide", no wonder you are lost in the wilderness. In just one example I looked at, I saw at least three errors.Here, my "guide".
This should be your guide instead. Pay close attention to what it says about overriding vs. extending event behavior as well as what it says about return values for the basic QObject::event() method.
robgeek (13th September 2015)
I really don't know anymore if is an event problem or what, because my code works "fine", i just have to click many times on a cell to get the correct value of (line, column).
I tried to change my code of post #11, i don't know if is what anda_skoa said, but i got the same problem. Nothing changed.
Qt Code:
if(event->button( ) == Qt::LeftButton) { cout << "(" << this->currentRow( ) << ", " << this->currentColumn( ) << ")" << endl; } else { } }To copy to clipboard, switch view to plain text mode
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:
Qt Code:
{ if(event->button( ) == Qt::LeftButton) { cout << "(" << this->currentRow( ) << ", " << this->currentColumn( ) << ")" << endl; } }To copy to clipboard, switch view to plain text mode
robgeek (13th September 2015)
Now is working fine. Thanks a lot!
Bookmarks