Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How do I open another window?

How do I open another window?

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 2 Posters 434 Views
  • 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 Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    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()
    
    jsulmJ 1 Reply Last reply
    0
    • M Mikeeeeee

      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()
      
      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @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
      1
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #3

        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?

        jsulmJ 1 Reply Last reply
        0
        • M Mikeeeeee

          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?

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by SGaist
          #4

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

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved