PySide - GUI inactive zone on the menu bar - python

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

Related

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: Updating icons when changing the themeSearchPaths()

I'm currently trying to enable switching the icon theme of an application during runtime.
The problem is that I just cant figure out how to trigger the objects to "refresh" their icons and pick them from the new QIcon.themeSearchPaths().
def change_icon(self):
style = QApplication.style()
if self.standart_icon_theme_active:
QIcon.setThemeSearchPaths([""]) # resetting to the 'default' folder
QIcon.setThemeName(u"")
else:
QIcon.setThemeSearchPaths(["icons/"]) # the folder with my icons
QIcon.setThemeName(u"icons")
for btn in self.bttns:
btn.setIcon(style.standardIcon(getattr(QStyle, btn.objectName()))) # <= im searching for a signal or something to replace this
self.standart_icon_theme_active = not self.standart_icon_theme_active
What I currently have is a little demo Window with a lot of buttons, (which got created with a list of names of icons, so that their name equals the icon they have) in which each icon of each button gets updated when change_icon() gets triggered, and i'm searching for something like a builtin signal which I can emit to let Pyside update each icon on its own, or something in that way.
Any help would be appreciated.

Make second PyQt4 QMainWindow "detachable" from main application

I have a PyQt4 application with a QMainWindow. From within that program I launch another QMainWindow that is used to draw a matplotlib plot. My approach is based on Eli Benderskys way of integrating matplotlib with PyQt.
class QtMatplotlibWindow(QtGui.QMainWindow):
"""Plot window to display data, is created by main application"""
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
If I instantiate QtMatplotlibWindow with parent=None the resulting window will be completely "independent", meaning that it has its own icon in the taskbar and is completely "detached" from the main application. So, for instance, I can bring anther application, say Internet Explorer, to the front and subsequently bring only the Matplotlib window to the front, the actual application staying in the background. However using parent=None results in the matplotlib window being thrown off the stack and closed without my willing to do so at some seemingly random point in time.
If, on the other hand, I pass the instance of the main application as the parent the two windows are "tied together", meaning that I cannot view them independently of each other.
How can I achieve the "best of both worlds"? I'd like to pass the instance of the main application as the parent, so that the generated plots will only be closed if I close the main application, but I would also like the plot windows to be entirely independent in showing and moving. I would expect there to be some property of QMainWindow that would allow me exactly that. I hope I could phrase my question clear enought, I feel like I lack the appropriate terminology.
The fact that your second window disappears at random time indicates that it has been garbage collected. You must keep a python reference to all your windows. For instance append your newly created window to a list somwhere in your application: windowlist.append(QtMatplotlibWindow())

PyQt4 - Making a QIcon look active or "pressed down"

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)

Qt - Temporarily disable all events or window functionality?

I have a Qt program with many buttons, user-interactable widgets, etc.
At one stage in the program, I would like all the widgets to temporarily 'stop working'; stop behaving to mouse clicks and instead pass the event on to one function.
(This is so the User can select a widget to perform meta operations. Part explanation here: Get variable name of Qt Widget (for use in Stylesheet)? )
The User would pick a widget (to do stuff with) by clicking it, and of course clicking a button must not cause the button's bound function to run.
What is the correct (most abstracted, sensible) method of doing this?
(which doesn't involve too much new code. ie; not subclassing every widget)
Is there anything in Qt designed for this?
So far, I am able to retrieve a list of all the widgets in the program (by calling
QObject.findChildren(QtGui.QWidget)
so the solution can incorporate this.
My current horrible ideas are;
Some how dealing with all the applications events all the time in one
function and not letting through the events when I need the
application to be dormant.
When I need dormancy, make a new transparent widget which recieves
mouse clicks and stretch it over the entire window. Take coordinates
of click and figure out the widget underneath.
Somehow create a new 'shell' instance of the window.
THANKS!
(Sorry for the terrible write-up; in a slight rush)
python 2.7.2
PyQt4
Windows 7
You can intercept events send to specific widgets with QObject::installEventFilter.
graphite answered this one first so give credit where credit is due.
For an actual example in PySide, here's an example you might draw some useful code from:
my_app.py
from KeyPressEater import KeyPressEater
if __name__ == "__main__":
app = QApplication(sys.argv)
eater = KeyPressEater()
app.installEventFilter(eater)
KeyPressEater.py
class KeyPressEater(QObject):
# subclassing for eventFilter
def eventFilter(self, obj, event):
if self.ignore_input:
# swallow events
pass
else:
# bubble events
return QObject.eventFilter(self,obj,event)

Categories

Resources