Reputation: 1
i'm working with Python 2.7 in the API of a visualization-program. In its 2016-version i created a GUI with PySide and it was working guite good. Now in their new 2017-version they changed from PySide to PythonQt, so my imports and a few commands had to be changed, but it still works so far.
But if i close my GUI and try to proceed working, for example opening a current or new project the 2017-version is exiting, sometimes with, sometimes without error message, but that message does not help at all.
If i close my GUI-window the same way as in the 2016-version, the program is closed. The strange thing is that if i use the close command that i would need if i run my window standalone in Windows 7 Pro an error is shown in the program (Traceback (most recent call last): File "", line 1152, in closeEvent ValueError: slot quit() -> void requires QApplication instance as first argument.), my GUI is closed and i can continue working.
So i my GUI needs to be closed in a certain way, that i could not figure out so far.
My GUI is opened by calling the showMyGUI()-function in the programs terminal, where python commands can be executed or by pressing an F-button, where this function is linked to.
# -*- coding: utf-8 -*-
import sys, os
progVers = getVredVersion()[:1]
if progVers == "8": #2016-version
from PySide.QtCore import *
from PySide.QtGui import *
elif progVers == "9": #2017-version
from PythonQt.QtCore import *
from PythonQt.QtGui import *
class MainWindow(QWidget):
def __init__(self):
super(MainWindow, self).__init__()
grid = QGridLayout()
grid.setSpacing(10)
...
self.setWindowModality(Qt.ApplicationModal)
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.WindowMaximizeButtonHint)
self.show()
def closeEvent(self,event):
progVers = getVredVersion()[:1]
if progVers == "8":
QApplication.instance().quit()
elif progVers == "9":
QApplication.quit() #as used for standalone in Windows 7 Pro
event.accept()
def showMyGUI():
app = QApplication.instance()
window = MainWindow()
app.exec_()
keyF11 = vrKey(Key_F11)
keyF11.connect(showMyGUI)
Can anyone tell me how to close my GUI properly?
Upvotes: 0
Views: 520
Reputation: 1
My solution is:
MainWindow
is now inheriting form QDialog
and needs a parent (def __init__(self, parent=None
): and super(MainWindow, self).__init__(parent)
). When creating the MainWindow
-object the parent-window can be accessed with verdMainWindow()
in the 2016-version an with vrMainWindow
in the 2017-version. I create an object of that class in this way window=MainWindow(vrMainWindow)
.
Upvotes: 0