silent_sight
silent_sight

Reputation: 502

How to set QMenu tear-off window title?

I'm creating a custom ui in Maya 2017 which uses PyQt5 (well... technically PySide2, but it's essentially the same).

I've got a few CustomContextMenu popup menus that I've created in my ui and I've used popup.setTearOffEnabled(True) to be able to tear them off into a separate window (popup, being the QMenu item).

I cannot seem to figure out how to set the title for the resulting torn off window. Currently, each torn off window is titled "Maya-2017", but I'd like to give it a unique name for clarity. I've noticed that Maya's menu items with tear off functionality name the resulting window with the menu's name, so it would seem this is doable. Am I just missing something obvious?

I have tried using popup.setTitle('test name') on the QMenu thinking it would then name the tear off window this title, but it doesn't seem to do anything. Other than that, I'm at a loss.

Upvotes: 2

Views: 1027

Answers (1)

ekhumoro
ekhumoro

Reputation: 120608

I'm not sure whether torn-off menus appear the same on all platforms, but on my Linux system, they are shown as tool windows with a title-bar. So the title can be set like this:

menu = QMenu('File')
menu.setTearOffEnabled(True)
menu.setWindowTitle('File')

Upvotes: 2

Related Questions