Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How do I open another window?

    Qt for Python
    2
    4
    217
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Mikeeeeee last edited by

      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()
      
      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Mikeeeeee last edited by jsulm

        @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?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 1
        • M
          Mikeeeeee last edited by

          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?

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @Mikeeeeee last edited by SGaist

            @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]

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 2
            • First post
              Last post