Results 1 to 2 of 2

Thread: default contextMenu

  1. #1

    Default default contextMenu

    This may sound weird ...but
    Could anyone please give me a code which has a widget(a simple widget which draws a rectangle in a QHBox) and this widget should implement a DefaultContextMenu and could u please say what this "contextMenuEvent()" is and what are the options this DefaultContextMenu gives it is like "Close","Maximise","Minimise","Restore"


    Thanks In Advance
    Naveen

  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: default contextMenu

    There is no such thing as "default context menu" which would contain some default menu items. You need to construct the context menu by yourself. By changing the property QWidget::contextMenuPolicy changes the way context menu can be handled.

    The default value of this property is Qt:efaultContextMenu, which means the contextMenuEvent() handler is called. Other values are Qt::NoContextMenu, Qt::ActionsContextMenu, and Qt::CustomContextMenu. With Qt::CustomContextMenu, the signal customContextMenuRequested() is emitted.
    So one way to popup a context menu is to override your widget's context menu event handler. The example below shows a way to show a context menu. Most probably you don't want to construct the menu each time it needs to be shown, rather construct it elsewhere and only show it here.

    Qt Code:
    1. void YourWidget::contextMenuEvent(QContextMenuEvent* e)
    2. {
    3. QMenu menu(this);
    4. QAction* act = menu.addAction("Something");
    5. menu.exec(e->globalPos());
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Getting the name of the default style
    By gregsan in forum Qt Programming
    Replies: 4
    Last Post: 28th September 2011, 19:00
  2. Replies: 7
    Last Post: 12th January 2011, 22:01
  3. QTreeView default drag action
    By onamatic in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2010, 07:37
  4. Modify a ContextMenu
    By smarinr in forum Qt Programming
    Replies: 5
    Last Post: 10th May 2008, 17:41
  5. Getting default "system" palette[solved]
    By maverick_pol in forum Qt Programming
    Replies: 0
    Last Post: 2nd April 2008, 17:34

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
  •  
Qt is a trademark of The Qt Company.