KDE 4.7 PyKDE API Reference

- KDE's Python API

# KMenu Class Reference

`from PyKDE4.kdeui import *`

Inherits: QMenu → QWidget → QObject

## Detailed Description

A menu with keyboard searching

KMenu is a class for menus with keyboard accessibility for popups with many options and/or varying options. It acts identically to QMenu, with the addition of setKeyboardShortcutsEnabled() and setKeyboardShortcutsExecute() methods.

The keyboard search algorithm is incremental with additional underlining for user feedback.

Author:
  Daniel M. Duley <mosfet@kde.org>

Author:
  Hamish Rodda <rodda@kde.org>

## Signals
| aboutToShowContextMenu (KMenu menu, QAction menuAction, QMenu ctxMenu)
## Methods
| __init__ (self, QWidget parent=0)
| __init__ (self, QString title, QWidget parent=0)
QAction | addTitle (self, QString text, QAction before=0)
QAction | addTitle (self, QIcon icon, QString text, QAction before=0)
| closeEvent (self, QCloseEvent a0)
QMenu | contextMenu (self)
| contextMenuEvent (self, QContextMenuEvent e)
bool | focusNextPrevChild (self, bool next)
| hideContextMenu (self)
| hideEvent (self, QHideEvent a0)
| keyPressEvent (self, QKeyEvent e)
Qt::KeyboardModifiers | keyboardModifiers (self)
Qt::MouseButtons | mouseButtons (self)
| mousePressEvent (self, QMouseEvent e)
| mouseReleaseEvent (self, QMouseEvent e)
| setKeyboardShortcutsEnabled (self, bool enable)
| setKeyboardShortcutsExecute (self, bool enable)
## Static Methods
KMenu | contextMenuFocus ()
QAction | contextMenuFocusAction ()

## Signal Documentation

aboutToShowContextMenu | ( | KMenu | menu,
|  | QAction | menuAction,
|  | QMenu | ctxMenu
| ) |  |  |

connect to this signal to be notified when a context menu is about to be shown

Parameters:

  | menu | The menu that the context menu is about to be shown for
  | menuAction | The action that the context menu is currently on
  | ctxMenu | The context menu itself

Signal syntax:
  `QObject.connect(source, SIGNAL("aboutToShowContextMenu(KMenu*, QAction*, QMenu*)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QWidget | parent=0
| ) |  |  |

Constructs a KMenu.

__init__ | ( | self, |
|  | QString | title,
|  | QWidget | parent=0
| ) |  |  |

Constructs a KMenu.

Parameters:

  | title | The text displayed in a parent menu when it is inserted into another menu as a submenu.

Parameters:

  | parent | the parent QWidget object

QAction addTitle | ( | self, |
|  | QString | text,
|  | QAction | before=0
| ) |  |  |

Inserts a title item with the given icon and title.

QAction addTitle | ( | self, |
|  | QIcon | icon,
|  | QString | text,
|  | QAction | before=0
| ) |  |  |

Inserts a title item with the given icon and title.

closeEvent | ( | self, |
|  | QCloseEvent | a0
| ) |  |  |

QMenu contextMenu | ( |  | self ) |

Returns the context menu associated with this menu

contextMenuEvent | ( | self, |
|  | QContextMenuEvent | e
| ) |  |  |

bool focusNextPrevChild | ( | self, |
|  | bool | next
| ) |  |  |

hideContextMenu | ( |  | self ) |

Hides the context menu if shown

hideEvent | ( | self, |
|  | QHideEvent | a0
| ) |  |  |

keyPressEvent | ( | self, |
|  | QKeyEvent | e
| ) |  |  |

Qt::KeyboardModifiers keyboardModifiers | ( |  | self ) |

Return the state of the keyboard modifiers when the last menuitem was activated.

Qt::MouseButtons mouseButtons | ( |  | self ) |

Return the state of the mouse buttons when the last menuitem was activated.

mousePressEvent | ( | self, |
|  | QMouseEvent | e
| ) |  |  |

mouseReleaseEvent | ( | self, |
|  | QMouseEvent | e
| ) |  |  |

setKeyboardShortcutsEnabled | ( | self, |
|  | bool | enable
| ) |  |  |

Enables keyboard navigation by searching for the entered key sequence. Also underlines the currently selected item, providing feedback on the search.

Defaults to off.

Warning:
  calls to text() of currently keyboard-selected items will contain additional ampersand characters.

Warning:
  though pre-existing keyboard shortcuts will not interfere with the operation of this feature, they may be confusing to the user as the existing shortcuts will not work. In addition, where text already contains ampersands, the underline produced is likely to confuse the user (as this feature uses underlining of text to indicate the current key selection sequence).

setKeyboardShortcutsExecute | ( | self, |
|  | bool | enable
| ) |  |  |

Enables execution of the menu item once it is uniquely specified. Defaults to off.

## Static Method Documentation

KMenu contextMenuFocus | ( |  | ) |

Returns the KMenu associated with the current context menu

QAction contextMenuFocusAction | ( |  | ) |

returns the QAction associated with the current context menu