Results 1 to 6 of 6

Thread: different pop up menus wanted...

  1. #1
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question different pop up menus wanted...

    In Browsers, when you right-click on the web page background (i.e. white space) you get a Context menu, different from what you'd get on a text selection and again different from what you get on a "link" selection...I saw the same in Qt assistant too!



    How is this achieved in Qt4? Can the same also be applied to the items in QListWidget?

    Thanks

    Nupul

  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: different pop up menus wanted...

    Which ever way you are handling the context menu (see context menu policy), the QContextMenuEvent (or the QPoint in case of custom context menu) parameter contains the requested position.
    QListWidget provides you methods (QListWidget::itemAt()) which make it straightforward to check whether there is an item under the requested position or not.
    You'll just need to construct and show the appropriate context menu based on the position.
    J-P Nurmi

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

    nupul (8th April 2006)

  4. #3
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: different pop up menus wanted...

    Hi, following on from this, can someone please tell me how to use itemAt()?

    In my case, I want the context menu to appear only when a TreeWidgetItem from a particular TreeWidget is right clicked. Therefore I have set the context menu policy accordingly, but I don't know how to use itemAt to perform the check...

    Quote Originally Posted by jpn
    QListWidget provides you methods (QListWidget::itemAt()) which make it straightforward to check whether there is an item under the requested position or not.
    You'll just need to construct and show the appropriate context menu based on the position.
    Really appreciate your help on this

  5. #4
    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: different pop up menus wanted...

    Qt Code:
    1. // Qt::DefaultContextMenu
    2. void MyTreeWidget::contextMenuEvent(QContextMenuEvent* event)
    3. {
    4. QTreeWidgetItem* item = itemAt(event->pos());
    5. if (item)
    6. {
    7. // an item exists under the requested position
    8.  
    9. QMenu menu(this);
    10. // ...
    11. menu.exec(event->globalPos());
    12. }
    13. else
    14. {
    15. // there is no item under the requested position
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. The following 2 users say thank you to jpn for this useful post:

    mstegehu (25th February 2011), rooney (27th June 2006)

  7. #5
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: different pop up menus wanted...

    Is there a equivalent to itemAt for the QTableWidget ??????

  8. #6
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: different pop up menus wanted...

    Last edited by Ginsengelf; 11th February 2009 at 07:05. Reason: messed up link

Similar Threads

  1. Missing text in menus etc.
    By New2QT in forum Qt Tools
    Replies: 9
    Last Post: 18th December 2008, 00:51
  2. wanted to re-instantiate two classes from a class
    By salmanmanekia in forum General Programming
    Replies: 2
    Last Post: 22nd August 2008, 08:59
  3. Replies: 2
    Last Post: 27th June 2008, 19:02
  4. Maya Style Right Click Menus in Qt
    By dvmorris in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2007, 11:55
  5. Why are actions limited to menus and toolbars?
    By Paul Drummond in forum Qt Programming
    Replies: 16
    Last Post: 3rd March 2006, 12:05

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.