Skip to content

Can't add menu item to non-removable ROI #2931

@samtygier

Description

@samtygier

Short description

I'd like to be able to add a context menu item to an ROI object. In my specific case, so that I can add a change colour action. I expected to be able to add a new item to the existing menu, so that I get the nice benefits of the hierarchical menus. But the ROI menu is tied to it being removable.

Code to reproduce

So I would like this to give me a menu with "Test", but not "Remove ROI"

import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtWidgets

app = pg.mkQApp("ImageView Example")
win = pg.GraphicsView()
view = pg.ViewBox()
win.setCentralItem(view)
img = pg.ImageItem(np.zeros((100,100)))
view.addItem(img)
win.show()

roi = pg.ROI((10,10), (50,50), removable=False)
view.addItem(roi)

menu = roi.getMenu()
menu.addAction("Test")

if __name__ == '__main__':
    pg.exec()

If I set removable=True I get
removable
otherwise I get no context menu for the ROI

Expected behavior

Context menu with new item

Real behavior

No context menu

Tested environment(s)

  • PyQtGraph version: Current master '0.13.4.dev0'
  • Qt Python binding: PyQt5 5.15.10 Qt 5.15.2
  • Python version: 3.12.1
  • NumPy version: 1.26.4
  • Operating system: Fedora 39
  • Installation method: running from git, also with conda

Additional context

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