Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there have relationship between QWidget and QWindow after QWindow detach from QWidget?

Is there have relationship between QWidget and QWindow after QWindow detach from QWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    richie18
    wrote on last edited by richie18
    #1

    Steps:

    1. Start application A.
    2. Start application B.
    3. Click embed button in application B. Embed the application A to application B.
    4. Click popup button. Popup the application A.
    5. Click block button in application A. Application A run Infinite loop, can not respond to mouse operations.
    6. Application B's process also cannot respond to mouse operations.

    What's the reason?

    Application B code:

    # -*- coding: utf-8 -*-
    
    import sys
    import win32gui
    from PyQt5.QtGui import QWindow
    from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QHBoxLayout, QPushButton
    from PyQt5.QtCore import Qt
    
    
    class MyWidget(QWidget):
        def __init__(self, parent=None):
    	super(MyWidget, self).__init__(parent)
    	layout = QVBoxLayout(self)
    	btnLayout = QHBoxLayout()
    	embedBtn = QPushButton("embed")
    	popupBtn = QPushButton("popup")
    	btnLayout.addWidget(embedBtn)
    	btnLayout.addWidget(popupBtn)
    	layout.addLayout(btnLayout)
    
    	embedBtn.clicked.connect(self.embed)
    	popupBtn.clicked.connect(self.popup)
    
    	self.window = None
    	self.windowWidget = None
    	self.hwnd = None
            self.resize(400, 400)
    
        def embed(self):
    	# todo application title must be right
    	self.hwnd = win32gui.FindWindow(None, "block application")
    	if self.hwnd:
    		self.window = QWindow.fromWinId(self.hwnd)
    		self.windowWidget = QWidget.createWindowContainer(self.window)
    		self.layout().addWidget(self.windowWidget)
    		win32gui.SetParent(self.hwnd, int(self.winId()))
    
        def popup(self):
    	self.window.setParent(None)
    	self.window.setFlags(Qt.Window)
    	self.windowWidget.setParent(None)
    	self.windowWidget.destroy()
    	win32gui.SetParent(self.hwnd, 0)
    	win32gui.UpdateWindow(self.hwnd)
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        widget = MyWidget()
        widget.show()
        app.exec_()
    

    Application A code:

    # -*- coding: utf-8 -*-
    
    import sys
    from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton
    
    
    class MyWidget(QWidget):
        def __init__(self, parent=None):
            super(MyWidget, self).__init__(parent)
            self.setWindowTitle("block application")
            layout = QVBoxLayout(self)
            blockBtn = QPushButton("block process")
            layout.addWidget(blockBtn)
    
            blockBtn.clicked.connect(self.block)
            self.resize(300, 200)
    
        def block(self):
            import time
            while True:
    	    print(time.time())
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        widget = MyWidget()
        widget.show()
        app.exec_()
    
    1 Reply Last reply
    0
    • R Offline
      R Offline
      richie18
      wrote on last edited by
      #2

      The environment:
      Python 3.6.8
      PyQt 5.7.1
      pywin32-224-cp36-cp36m-win_amd64

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        @richie18 said in Is there have relationship between QWidget and QWindow after QWindow pop up?:

        Block the application A by manual.

        What do you mean by that ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        R 2 Replies Last reply
        0
        • SGaistS SGaist

          Hi,

          @richie18 said in Is there have relationship between QWidget and QWindow after QWindow pop up?:

          Block the application A by manual.

          What do you mean by that ?

          R Offline
          R Offline
          richie18
          wrote on last edited by
          #4

          @SGaist said in Is there have relationship between QWidget and QWindow after QWindow pop up?:

          lock the application A by manua

          Block the application A's process after application A pop up from application B. For example, run code in application A below:

          import time
          while True:
              print(time.time())
          
          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            @richie18 said in Is there have relationship between QWidget and QWindow after QWindow pop up?:

            Block the application A by manual.

            What do you mean by that ?

            R Offline
            R Offline
            richie18
            wrote on last edited by
            #5

            @SGaist

            Use code below as application A.
            When application A is poped up, click the 'block process' button in applicaiton A. Then application B's process is also blocked.

            # -*- coding: utf-8 -*-
            
            import sys
            from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton
            
            
            class MyWidget(QWidget):
                def __init__(self, parent=None):
            	super(MyWidget, self).__init__(parent)
            	self.setWindowTitle("block application")
            	layout = QVBoxLayout(self)
            	blockBtn = QPushButton("block process")
            	layout.addWidget(blockBtn)
            
            	blockBtn.clicked.connect(self.block)
            	self.resize(300, 200)
            
                def block(self):
            	import time
            	while True:
            		print(time.time())
            
            
            if __name__ == '__main__':
                app = QApplication(sys.argv)
                widget = MyWidget()
                widget.show()
                app.exec_()
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Intriguing... Out of curiosity, what is the use case of "blocking" the application ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              R 1 Reply Last reply
              0
              • SGaistS SGaist

                Intriguing... Out of curiosity, what is the use case of "blocking" the application ?

                R Offline
                R Offline
                richie18
                wrote on last edited by richie18
                #7

                @SGaist

                Maybe I am not expressing correctly.
                “blocking” Means that application cannot respond to mouse operations

                May be follow the steps below to make it clear.

                Steps:

                1. Start application A.
                2. Start application B.
                3. Click embed button in application B. Embed the application A to application B.
                4. Click popup button. Popup the application A.
                5. Click block button in application A. Application A run Infinite loop, can not respond to mouse operations.
                6. Application B's process also cannot respond to mouse operations.
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  I would try to check with the event dispatchers if you can find something there.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  R 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    I would try to check with the event dispatchers if you can find something there.

                    R Offline
                    R Offline
                    richie18
                    wrote on last edited by richie18
                    #9

                    @SGaist

                    Application A's block() add code processEvents(), it seems ok. But native windows cannot be handled this way.
                    So, I'm not sure relationship between two application when they are detached. And how to solve?

                    def block(self):
                        import time
                        while True:
                    	print(time.time())
                            QApplication.processEvents()
                    
                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      You should check the the win32gui module developer, he may have some insight as to what is happening.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      R 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        You should check the the win32gui module developer, he may have some insight as to what is happening.

                        R Offline
                        R Offline
                        richie18
                        wrote on last edited by
                        #11

                        @SGaist

                        I'm not use win32gui.setParent(), also has this problem.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          As already suggested, contact the module author.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0

                          • Login

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