Skip to content

Right-clicking adds to plotItem.vb.menu.actions() #2289

@flokoenig

Description

@flokoenig

Short description

Opening the context-menu via right-clicking adds an entry to the list returned by plotItem.vb.menu.actions(). Tbh this behaviour didn't lead to complications for me, but I don't think it should behave like this.

Code to reproduce

In REPL

import pyqtgraph as pg

p = pg.plot([1,2,3,[4,5,6])
len(p.plotItem.vb.menu.actions()) # = 4
# now right-click in plot window
len(p.plotItem.vb.menu.actions()) # = 7
# now right-click in plot window
len(p.plotItem.vb.menu.actions()) # = 8
# repeated right clicking and evaluation of len(...) shows always + 1

Expected behavior

After first right-click, the actions-list should be constant (at 7 in this case).

Tested environment(s)

  • PyQtGraph version: 0.12.4
  • Qt Python binding: PyQt6 6.3.0 Qt 6.3.0
  • Python version: 3.9.2

Additional context

It might be due to what GraphicsScene.addParentContextMenus is doing:

menusToAdd = []
while item is not self:
item = item.parentItem()
if item is None:
item = self
if not hasattr(item, "getContextMenus"):
continue
subMenus = item.getContextMenus(event) or []
if isinstance(subMenus, list): ## so that some items (like FlowchartViewBox) can return multiple menus
menusToAdd.extend(subMenus)
else:
menusToAdd.append(subMenus)
if menusToAdd:
menu.addSeparator()

where it looks like it might in this case always call addSeparator. I'm not entirely sure, though.

BTW: the reason I came to this was, because I wanted to remove some of the entries of the contextmenu, as they don't work with the data I am plotting (different points have different brushes which clashes with some plot options).

Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions