# eric7.EricWidgets.EricModelMenu

Module implementing a menu populated from a QAbstractItemModel.

### Global Attributes

None

### Classes

EricModelMenu | Class implementing a menu populated from a QAbstractItemModel.

### Functions

None

## EricModelMenu

Class implementing a menu populated from a QAbstractItemModel.

### Signals

activated(QModelIndex)
  emitted when an action has been triggered

### Derived from

QMenu

### Class Attributes

None

### Class Methods

None

### Methods

EricModelMenu | Constructor
__aboutToShow | Private slot to show the menu.
__actionTriggered | Private slot to handle the triggering of an action.
__makeAction | Private method to create an action.
clear | Public method to clear the menu.
createBaseMenu | Public method to get the menu that is used to populate sub menu's.
createMenu | Public method to put all the children of a parent into a menu of a given length.
dragEnterEvent | Protected method to handle drag enter events.
dropEvent | Protected method to handle drop events.
firstSeparator | Public method to get the first separator.
index | Public method to get the index of an action.
makeAction | Public method to create an action.
maxRows | Public method to get the maximum number of entries to show.
model | Public method to get a reference to the model.
mouseMoveEvent | Protected method to handle mouse move events.
mousePressEvent | Protected method handling mouse press events.
mouseReleaseEvent | Protected method handling mouse release events.
postPopulated | Public method to add any actions after the tree.
prePopulated | Public method to add any actions before the tree.
removeEntry | Public method to remove a menu entry.
resetFlags | Public method to reset the saved internal state.
rootIndex | Public method to get the index of the root item.
separatorRole | Public method to get the role of the separator.
setFirstSeparator | Public method to set the first separator.
setMaxRows | Public method to set the maximum number of entries to show.
setModel | Public method to set the model for the menu.
setRootIndex | Public method to set the index of the root item.
setSeparatorRole | Public method to set the role of the separator.
setStatusBarTextRole | Public method to set the role of the status bar text.
statusBarTextRole | Public method to get the role of the status bar text.

### Static Methods

None

#### EricModelMenu (Constructor)

EricModelMenu(parent=None)

Constructor

parent
  reference to the parent widget (QWidget)

#### EricModelMenu.__aboutToShow

__aboutToShow()

Private slot to show the menu.

#### EricModelMenu.__actionTriggered

__actionTriggered(action)

Private slot to handle the triggering of an action.

action
  reference to the action that was triggered (QAction)

#### EricModelMenu.__makeAction

__makeAction(idx)

Private method to create an action.

idx
  index of the item to create an action for (QModelIndex)

Return:
  reference to the created action (QAction)

#### EricModelMenu.clear

clear()

Public method to clear the menu.

#### EricModelMenu.createBaseMenu

createBaseMenu()

Public method to get the menu that is used to populate sub menu's.

Return:
  reference to the menu (EricModelMenu)

#### EricModelMenu.createMenu

createMenu(parent, max_, parentMenu=None, menu=None)

Public method to put all the children of a parent into a menu of a given length.

parent
  index of the parent item (QModelIndex)
max_
  maximum number of entries (integer)
parentMenu
  reference to the parent menu (QMenu)
menu
  reference to the menu to be populated (QMenu)

#### EricModelMenu.dragEnterEvent

dragEnterEvent(evt)

Protected method to handle drag enter events.

evt
  reference to the event (QDragEnterEvent)

#### EricModelMenu.dropEvent

dropEvent(evt)

Protected method to handle drop events.

evt
  reference to the event (QDropEvent)

#### EricModelMenu.firstSeparator

firstSeparator()

Public method to get the first separator.

Return:
  row number of the first separator (integer)

#### EricModelMenu.index

index(action)

Public method to get the index of an action.

action
  reference to the action to get the index for (QAction)

Return:
  index of the action (QModelIndex)

#### EricModelMenu.makeAction

makeAction(icon, text, parent)

Public method to create an action.

icon
  icon of the action (QIcon)
text
  text of the action (string)
parent
  reference to the parent object (QObject)

Return:
  reference to the created action (QAction)

#### EricModelMenu.maxRows

maxRows()

Public method to get the maximum number of entries to show.

Return:
  maximum number of entries to show (integer)

#### EricModelMenu.model

model()

Public method to get a reference to the model.

Return:
  reference to the model (QAbstractItemModel)

#### EricModelMenu.mouseMoveEvent

mouseMoveEvent(evt)

Protected method to handle mouse move events.

evt
  reference to the event (QMouseEvent)

#### EricModelMenu.mousePressEvent

mousePressEvent(evt)

Protected method handling mouse press events.

evt
  reference to the event object (QMouseEvent)

#### EricModelMenu.mouseReleaseEvent

mouseReleaseEvent(evt)

Protected method handling mouse release events.

evt
  reference to the event object (QMouseEvent)

#### EricModelMenu.postPopulated

postPopulated()

Public method to add any actions after the tree.

#### EricModelMenu.prePopulated

prePopulated()

Public method to add any actions before the tree.

Return:
  flag indicating if any actions were added

#### EricModelMenu.removeEntry

removeEntry(idx)

Public method to remove a menu entry.

idx
  index of the entry to be removed (QModelIndex)

#### EricModelMenu.resetFlags

resetFlags()

Public method to reset the saved internal state.

#### EricModelMenu.rootIndex

rootIndex()

Public method to get the index of the root item.

Return:
  index of the root item (QModelIndex)

#### EricModelMenu.separatorRole

separatorRole()

Public method to get the role of the separator.

Return:
  role of the separator (integer)

#### EricModelMenu.setFirstSeparator

setFirstSeparator(offset)

Public method to set the first separator.

offset
  row number of the first separator (integer)

#### EricModelMenu.setMaxRows

setMaxRows(rows)

Public method to set the maximum number of entries to show.

rows
  maximum number of entries to show (integer)

#### EricModelMenu.setModel

setModel(model)

Public method to set the model for the menu.

model
  reference to the model (QAbstractItemModel)

#### EricModelMenu.setRootIndex

setRootIndex(index)

Public method to set the index of the root item.

index
  index of the root item (QModelIndex)

#### EricModelMenu.setSeparatorRole

setSeparatorRole(role)

Public method to set the role of the separator.

role
  role of the separator (integer)

#### EricModelMenu.setStatusBarTextRole

setStatusBarTextRole(role)

Public method to set the role of the status bar text.

role
  role of the status bar text (integer)

#### EricModelMenu.statusBarTextRole

statusBarTextRole()

Public method to get the role of the status bar text.

Return:
  role of the status bar text (integer)

Up