How do I open another window?
-
Hi!
How do I open another window?
It is main window:class MainWindow(QObject): def __init__(self): super(MainWindow, self).__init__() self.ui = uic.loadUi("mainWindow.ui")
It is start main window:
if __name__ == '__main__': app = QgsApplication([], True) app.initQgis() app.setPkgDataPath("./share/qgis") # print(app.srsDatabaseFilePath()) mainWindow = MainWindow() mainWindow.showWindow() app.exec()
it is second window:
class Polygons(QObject): def __init__(self): super(Polygons, self).__init__() self.ui = uic.loadUi("polygons.ui")
If I do this, then window not chowing:
polygons = Polygons() polygons.showWindow()
-
Hi!
How do I open another window?
It is main window:class MainWindow(QObject): def __init__(self): super(MainWindow, self).__init__() self.ui = uic.loadUi("mainWindow.ui")
It is start main window:
if __name__ == '__main__': app = QgsApplication([], True) app.initQgis() app.setPkgDataPath("./share/qgis") # print(app.srsDatabaseFilePath()) mainWindow = MainWindow() mainWindow.showWindow() app.exec()
it is second window:
class Polygons(QObject): def __init__(self): super(Polygons, self).__init__() self.ui = uic.loadUi("polygons.ui")
If I do this, then window not chowing:
polygons = Polygons() polygons.showWindow()
@Mikeeeeee said in How do I open another window?:
If I do this, then window not chowing:
polygons = Polygons()
polygons.showWindow()It should be
polygons.show()
Polygons needs to be derived from QWidget. QObject is not visual!
But, where is this code actually located? -
I do this
class Polygons(QtWidgets.QWidget):
and this
polygons = Polygons() # polygons.showWindow() polygons.show()
but the window never appeared. When I click the button, I try to open a new window. What else needs to be fixed?
@Mikeeeeee said in How do I open another window?:
What else needs to be fixed?
I guess your polygons is a LOCAL variable which is destroyed as soon as it leaves its scope.
Make it member:self._polygons = Polygons() self._polygons.show()
[edit: added missing self SGaist]