PySide QMenuBar Cross Platform - python

I have a PySide (Qt) application that utilizes an mdiArea in the main window and then populates this area with a number of QWidgets (windows). These QWidgets have menu bars added to a vertical layout.
This works great on Linux and Windows, but fails on OS X, i.e. only the QMainWindow menu bar is shown. A menubar added to a QWidget that is a sub window of an mdiArea is never displayed. What is the normal method for supporting menubars in sub windows across all platforms? Is it possible to put the menu into a toolbar?
Techniques in python or C++ are appreciated - whether a piece of code or a broader design pattern.

Related

QTextEdit / whole UI of PyQt5 behaves differently on Android when virtual keyboard active

I have a small PyQt5 / pyqtdeploy based app that runs on desktop systems as well as on Android. Inside the MainWindow there is a QTextEdit widget with its textChanged signal connected to some method.
Everything seems to work well on Android until I enter the QTextEdit instance and the virtual keyboard pops up. I can enter text but on_textChanged() will only be called when I leave the text field and thus the keyboard disappears.
It also looks like as the whole update() method of my MainWindow doesn't get called as well.
Is the Qt event system somehow disabled when the virtual keyboard is active?
(I'm using PyQt5.15.0 on Linux and Android 9)

How to open a separate UI Window from QMainWindow?

So I have a MainWindow.ui in the class QMainWindow. I also have a separate QWidget and QDialog window (not sure which one is better to use) that I would like to open by using the menu bar from MainWindow.ui. I know that I can simply do something like:
self.main_layout.addWidget(self.form_widget)
or
flashC = flashCard()
flashC.show()
But I want to do this in Qt Designer, so that I don't have to change the .py file every time I run pyuic5 (since these changes will be replaced upon running.)
My question is, how do I make it so that QMainWindow can open other windows that I make later from within Qt Designer. Right now I can't access any other windows in my signal/slot editor.
I've been trying to figure this out and the books and other resources that I've looked at haven't pointed me in the right direction. I just want to know if it's possible to call other windows from within Qt Designer.
You can have multiple QMainWindow in your application. To create a second window simply define it in Qt Designer as you have for your current window, then import and create an instance of it.
Remember it will only appear once you call .show()

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.
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')

PySide - GUI inactive zone on the menu bar

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

modelPanel (Maya) in QT UI using PySide

I am having an issue parenting a modelPanel (Viewport) into a predefined space in a QT Ui created in Designer. When I try to parent the modelPanel and run the script in Maya, it immediately crashes.
Example:
Create a new window in Qt Designer, and drag and drop a vertical layout in the window and save the ui. In the python class when do the parenting i do it as follows:
pm.modelPanel('modelPanelA', p = 'verticalLayout')
The window is drawn and I see the viewport, BUT the window is not scaleable. Which it has to be. So back in Qt Designer I got to Form > Lay Out as Grid. Now the vertical layout is scalable. I save the UI, reload the class, and create the window. Maya crashes! Why?

Categories

Resources