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.
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')
Related
I am working on a Gtk+ 3 application that is likely to be used fullscreen most of the time, but needs to be switched between fullscreen and non-fullscreen, while maintaining access to the controls located in the header bar. The problem is, since the headerbar is part of the window decorations, it gets hidden when the window goes fullscreen.
My current kludge so ensure the controls are always available works like this:
Setup
create a Gtk.Window with vertical Gtk.Box as first child
create a custom Gtk.HeaderBar (w/ added full screen togglebutton)
set window's titlebar as my custom Gtk.HeaderBar
add all the window's content to the Gtk.Box
When window goes fullscreen
remove the Gtk.HeaderBar from the Gtk.Window titlebar
pack the Gtk.HeaderBar into the Gtk.Box (window's first child).
This results in the Gtk.HeaderBar being at the bottom of the window, so
re-position the Gtk.HeaderBar to the top of the Gtk.Box
When the window goes un-fullscreen
remove the Gtk.HeaderBar from the gtk.Box
set it as the Gtk.Window's titlebar
This results in the following Gtk-warning: gtk_window_set_titlebar() called on a realized window (who cares, just a warning)
This works, but it seems like very much of a hack, and more complicated than it should have to be. Am I missing something and there is a more straightforward approach?
I know several Gtk+ 3 based apps have the header bar behavior I am after (gedit for example), but I have not been able to determine how that is implemented. Any insight would be greatly appreciated.
Also, here is a GitHub gist with a full working example of my current hacky solution: https://gist.github.com/KurtJacobson/6b045b6fc38907a2f18c38f6de2929e3
I will accept answers in any (programming) language.
I wanted to ask if it is possible to draw a child window inside a parent window so that it will only be able to move inside the parent window and won't be able to move out of the parent window bounds.
If you mean having actual windows with title bar, menu, status bar etc. inside the parent window then the answer is:
No, Tcl/Tk and by extension Tkinter does not support this with its standard widgets.
There have been efforts in the past to implement widgets which emulate MDI as you can see on the TCL wiki, but most of them are over a decade old. You will probably have to implement it yourself or choose a different GUI toolkit if you really need to implement this kind of UI design.
If you do it yourself, you can use the Frame widget as the subwindow, and use place to put it in the containing window. Or, you can create it as an object on a canvas. You'll have to write all of the code to give the inner window borders and a title bar, and to manage moving it around, iconifying it, etc.
I am coding a GUI in PySide for a couple of month now. This soft is half developed using Qt designer and half hard coded. It is a MainWindow soft with a central widget and a lot of docks.
Recently I realized that the menu bar (and a tiny bit of the task bar) had a zone which was 'inactive', ie the mouse can not access the menus directly. This zone is highlighted in green in the picture.
The menus are working, since when I click on the right half of the configure menu button, I can access the File or Edit menu as shown in the following picture
The code translating the Qt designer output into python code is
call pyside-uic mainWindow.ui -o uiMainWindow.py
call pyside-rcc -o fittingRessources_rc.py pathtoressources\fittingRessources.qrc
I have tried to remove the icon of the soft. Move the task bars (in which case the buttons of the task bar are entirely active again). I have tried to remove the icons of the task bar. Nothing made a difference.
I can provide code if necessary, but first I was wondering if any of you already encountered this issue? and how it solved it? since it seems a bit ackward...
Cheers
The error appeared only when I was adding certain docks to the MainWindow using the following code:
self.variablesDock = VariablesDock(self,self.dataCurve)
where self is mainWindow. The VariablesDock class is the following
class VariablesDock(QWidget):
'''
Allows to define variables
'''
def __init__(self, mainWindow, dataCurve):
'''
Constructor
'''
super(VariablesDock,self).__init__(mainWindow)
self.mainWindow = mainWindow
self.dataCurve = dataCurve
self.variablesDockWidget = QtGui.QDockWidget(mainWindow)
... skip some code ...
self.variablesDockWidget.setWidget(self.dockWidgetContents)
mainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.variablesDockWidget)
self.variablesDockWidget.setWindowTitle("Variables")
if I change the line super(VariablesDock,self).__init__(mainWindow) into
super(VariablesDock,self).__init__(None)
the error disappeared.
Cheers
I have a QMainWindow with a toolbar that has a bunch of QIcon buttons. Clicking these buttons switches between widgets in a QStackedWidget. Basically, the buttons function as tabs, opening different parts of the program. Now, what I want to do is make a specific button look pressed down when the corresponding widget is active, so it's easier to see which part of the program is active. Like this:
I rephrased it 20 different ways while Googling and checked out the manual but I'm still at a loss. I'm probably missing something painfully obvious here.
Of course I was missing something painfully obvious :P Here's the solution:
# Create the button and make it checkable
self.testButton = QtGui.QAction(QtGui.QIcon('images/icons/test.png'), 'Test', self)
self.testButton.setCheckable(True)
# Mark the button as checked
self.testButton.setChecked(True)
Is there a quick way to clear the menu bar i.e. Remove all menus in PyQt.
The reason I ask is that I am developing a modular application. Each module provides it's own menus and gives a weighting to where that menu should appear. Each module can also add a menuAction to another modules menu, however when that happens it changes the order of the menus. What i want to do is when the menus have finished being created is to remove them all and then re add them.
I know this will work because I can re add them now and they appear in the correct order but all the previous menus are still there.
did you try QMenu.clear (self)
mymenu = QtGui.QMenu("Menu")
mymenu.clear()