Results 1 to 3 of 3

Thread: Right Click in QTableView

  1. #1
    Join Date
    Apr 2014
    Posts
    59
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Right Click in QTableView

    I am using activated() to open a file in one of my columns, but that only works with the enter key. The only way I could find to allow using a mouse was to subclass QTableView and use mousePressedEvent(). This seems to be working, but it also seems too simple, and I am unsure if I did it right, or if I should not have done something more. All I did was:
    Qt Code:
    1. void TableView::mousePressEvent(QMouseEvent *event)
    2. {
    3. QPoint pos = event->pos();
    4. QPersistentModelIndex index = indexAt(pos);
    5.  
    6. if(event->button() == Qt::RightButton)
    7. emit activated(index);
    8. else
    9. QAbstractItemView::mousePressEvent(event);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Is that the proper way to do it?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Right Click in QTableView

    That is enough.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Apr 2014
    Posts
    59
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Right Click in QTableView

    Thanks for the conformation. I think I have this part of my application roughed out enough to move on, and have started the next part.

Similar Threads

  1. Replies: 1
    Last Post: 11th July 2014, 09:26
  2. Replies: 4
    Last Post: 11th January 2014, 03:06
  3. Telling apart single click and double click in QTableView
    By jgirlich in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2013, 14:27
  4. Replies: 2
    Last Post: 16th July 2012, 12:40
  5. QTableView deselecting on click
    By andytork in forum Qt Programming
    Replies: 4
    Last Post: 19th January 2009, 17:51

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.