I do not understand why in the book Rapid GUI Programming with Python and Qt, a context menu is added to a central widget by calling addActions()
on the main window (self
), like so (p. 180):
self.addActions(self.imageLabel,
(editInvertAction, …))
where self
is a QMainWindow
, and imageLabel
is a QLabel
set as the central widget with
self.imageLabel.setContextMenuPolicy(Qt.ActionsContextMenu) # Added actions will be put in a context menu
self.setCentralWidget(self.imageLabel)
Now, why would the main window be associated in some way (through self.addActions()
) to the context menu of the central widget? Isn't it enough to call addActions()
directly on the central widget? In fact, the following does create a context menu:
self.imageLabel.addActions((editInvertAction, …))
Why doesn't the book example the context menu this way? isn't this equivalent to the more involved self.addActions(…)
form?
PS: I even see that the documentation for QMainWindow.addActions() does not even mention any first argument (self.imageLabel
, above)! I'm completely lost as to why the book uses the first snippet above instead of the last one… Help! :)