Results 1 to 2 of 2

Thread: right click in TableView?

  1. #1
    Join Date
    Aug 2007
    Posts
    19
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default right click in TableView?

    How would I add a rightClick function to a QTableView with a subclassed QAbstractTableModel? Currently, I have (and would like to replace) a Q3Table with Q3Popupmenu connected through a mousepressed signal from Q3Table.

    Thanks!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: right click in TableView?

    Reimplement QWidget::contextMenuEvent(). You can get the item (if any) at requested position with QContextMenuEvent::pos() and QAbstractItemView::indexAt(), more or less like:
    Qt Code:
    1. void MyTableView::contextMenuEvent(QContextMenuEvent* event)
    2. {
    3. QModelIndex index = indexAt(event->pos());
    4. if (index.isValid())
    5. {
    6. // ...
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    There are also alternative ways of handling context menu. See QWidget::contextMenuPolicy for more details.
    J-P Nurmi

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

    nategoofs (14th August 2007)

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 15:12
  2. QGraphicItem mouse click detection
    By PrimeCP in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 12:35
  3. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 05:32
  4. Items in QListView should sort on Header Click
    By vinnu in forum Qt Programming
    Replies: 14
    Last Post: 10th November 2006, 13:49
  5. Replies: 5
    Last Post: 12th January 2006, 16:40

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.