Results 1 to 16 of 16

Thread: Working with mouse events: How to do that with QTableWidget?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: Working with mouse events: How to do that with QTableWidget?

    If that is your actual code then you are forgetting to call the base class implementation of mousePressEvent().
    Sorry, i didn't understand! All code examples i saw look alike my code. How can i do that?

    Here, my "guide".

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Working with mouse events: How to do that with QTableWidget?

    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.

    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.

  3. The following user says thank you to d_stranz for this useful post:

    robgeek (13th September 2015)

  4. #3
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: Working with mouse events: How to do that with QTableWidget?

    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:
    1. void Table::mousePressEvent(QMouseEvent *event) {
    2. if(event->button( ) == Qt::LeftButton) {
    3. cout << "(" << this->currentRow( ) << ", " << this->currentColumn( ) << ")" << endl;
    4. }
    5. else {
    6. QWidget::mousePressEvent( event );
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Working with mouse events: How to do that with QTableWidget?

    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:
    1. void Table::mousePressEvent(QMouseEvent *event)
    2. {
    3. QTableWidget::mousePressEvent( event );
    4. if(event->button( ) == Qt::LeftButton)
    5. {
    6. cout << "(" << this->currentRow( ) << ", " << this->currentColumn( ) << ")" << endl;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to d_stranz for this useful post:

    robgeek (13th September 2015)

  7. #5
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: Working with mouse events: How to do that with QTableWidget?

    Now is working fine. Thanks a lot!

Similar Threads

  1. Replies: 2
    Last Post: 16th July 2012, 12:40
  2. Replies: 3
    Last Post: 8th October 2011, 09:46
  3. QTableWidget + QEventFilter: cannot filter mouse events
    By trallallero in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2011, 08:16
  4. Replies: 2
    Last Post: 2nd April 2008, 14:19
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.