I'm writing some scripts on Python console in QGIS. I have been stuck since a lot of time because I'm not able to recall a MainWindow class object from an other script. I've created a main menu with inside a combobox. The idea is that when the user selects an option from this dropdown list, an other window opens. The problem is that this window opens for just a moment and then closes itself. Here the code.
this is the main menu's script (proofRequest.py) (not whole)
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import proofRequest as pr
def startButton(self):
x = self.comboBox.currentIndex()
if x == 3:
win = pr.MainWindow()
win.show()
While this is the script of the window which I would open (just not whole)
import sys
from PyQt5.QtWidgets import *
from qgis.utils import iface
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class MainWindow(QMainWindow):
def __init__(self, parent=None, *args):
super(MainWindow, self).__init__(parent = parent)
self.setWindowTitle("QDialog Example")
self.resize(350, 300)
#layout = QVBoxLayout()
print("sono qui")
self.button1Ok = QPushButton("Ok", self)
self.button2Annulla = QPushButton("Annulla", self)
self.button1Ok.setGeometry(30,180,130,40)
self.button2Annulla.setGeometry(180,180,130,40)
label = QLabel("Seleziona un comune con edifici, poi clicca su ok", self)
label.setAlignment(Qt.AlignHCenter)
label.setGeometry(10, 50, 330, 30)
self.button1Ok.clicked.connect(self.avvia)
self.button2Annulla.clicked.connect(self.cancella)