Python Forum
[PyQt] PyQt trigger leaveEvent in parent
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] PyQt trigger leaveEvent in parent
#2
Okay first I tweaked your code to be more pythonic/pyqtish in form removing some of the dangerous items and replacing PyQt4 references with PyQt5 references if you have any questions as to why do ask so that I can explain the whys of it -- so without further ado here she be
from PyQt5.QtWidgets import QApplication, QDialog, QVBoxLayout
from PyQt5.QtWidgets import QFrame, QLabel
  
class CustomWidget(QFrame):
    def __init__(self, Name):
        QFrame.__init__(self)
        self.setFrameStyle(QFrame.StyledPanel)

        self.WdgtName = Name
        self.lblName = QLabel(self.WdgtName)

        VBox = QVBoxLayout()
        VBox.addWidget(self.lblName)

        self.setLayout(VBox)
 
    def enterEvent(self, event):
        print('Entering ', self.WdgtName)
 
    def leaveEvent(self, event):
        print('Leaving ', self.WdgtName)

class TestWindow(QDialog):
    def __init__(self):
        QDialog.__init__(self)

        self.resize(640, 480)

        self.Widget1 = CustomWidget('One')
        self.Widget2 = CustomWidget('Two')
 
        self.Widget1.layout().addWidget(self.Widget2)

        MainLayout = QVBoxLayout()
        MainLayout.addWidget(self.Widget1)

        self.setLayout(MainLayout)
 
 
if __name__ == '__main__':
    MainEventThread = QApplication([])

    MainApp = TestWindow()
    MainApp.show()

    MainEventThread.exec()
Now when executing this upon Entering One -- It denotes this upon Entering Two it denotes this BUT it does not denote we have left One because we have not. This because Two is contained within One. If I go back to One then it denotes I have left Two but if while in Two I move the mouse outside the entire window then it denotes that I have left Two and One -- in that order
Reply


Messages In This Thread
PyQt trigger leaveEvent in parent - by kainev - Dec-01-2019, 08:15 AM
RE: PyQt trigger leaveEvent in parent - by Denni - Dec-02-2019, 07:18 PM
RE: PyQt trigger leaveEvent in parent - by kainev - Dec-03-2019, 01:27 AM
RE: PyQt trigger leaveEvent in parent - by Denni - Dec-03-2019, 03:53 PM
RE: PyQt trigger leaveEvent in parent - by Denni - Dec-03-2019, 04:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] What causes this pop-up to trigger? Oshadha 2 1,793 Dec-17-2020, 08:37 AM
Last Post: Oshadha
  Ho can I get the first parent of a class? panoss 2 3,624 Jan-10-2017, 08:10 AM
Last Post: panoss

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020