Results 1 to 2 of 2

Thread: context menu advice

  1. #1
    Join Date
    Jun 2006
    Location
    San Jose, CA
    Posts
    53
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default context menu advice

    Hi,

    I would need some advice how to implement context menus the right way.

    Here the situation:

    I have a main widget which contains two tableviews each assigned to a model. Right click over a row triggers a different action for each of the two tables.

    scenario 1:
    subclass tableview and implement
    void MyTableView1::contextMenuEvent(QContextMenuEvent* e) and
    void MyTableView2::contextMenuEvent(QContextMenuEvent* e)
    Check if
    QModelIndex index = indexAt(e->pos());
    is valid
    Problem 1: hard to get from here to the model data to change something.

    scenario 2:
    Implement contextMenuEvent(QContextMenuEvent* e) for main window and check if
    QModelIndex index = table1->indexAt(e->pos());
    QModelIndex index = table2->indexAt(e->pos());
    are valid.
    Problem 2: e->pos() gives me the position releative to the main window. Is there a way to translate these positions relative to the tableViews?

    So, in summary what is the correct way to implement context menus: globally or relative to the widget

    Thanks.

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

    Default Re: context menu advice

    Quote Originally Posted by larry104 View Post
    Problem 1: hard to get from here to the model data to change something.
    Why? You can access the model through QAbstractItemView::model().
    Qt Code:
    1. model()->setData(index, data, role);
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by larry104 View Post
    Problem 2: e->pos() gives me the position releative to the main window. Is there a way to translate these positions relative to the tableViews?
    Yes, see docs for QWidget::mapFrom*() and QWidget::mapTo*().
    J-P Nurmi

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

    larry104 (4th October 2006)

Similar Threads

  1. Context Menu on QTableWidget
    By ankurjain in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2009, 09:52
  2. Qt's optimized OpenGL context switching
    By sverhoff in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 16:40
  3. Context OpenGL
    By mickey in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2006, 21:13
  4. Q3TextEdit custom context menu
    By bcteh_98 in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 21:00
  5. Tracking separators in a menu (insertSeparator)
    By PrimeCP in forum Qt Programming
    Replies: 4
    Last Post: 25th January 2006, 18:10

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.