Ticket #4983: test.py

File test.py, 1.2 KB (added by Eric Pettersen, 2 years ago)

PyQt6 example demonstrating problem

Line 
1from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QComboBox, QVBoxLayout
2
3# Only needed for access to command line arguments
4import sys
5
6# You need one (and only one) QApplication instance per application.
7# Pass in sys.argv to allow command line arguments for your app.
8# If you know you won't use command line arguments QApplication([]) works too.
9app = QApplication(sys.argv)
10
11# Create a Qt widget, which will be our window.
12window = QWidget()
13layout = QVBoxLayout()
14window.setLayout(layout)
15layout.addWidget(QLabel("Test case"))
16class DebuggingQComboBox(QComboBox):
17 def dragEnterEvent(self, event):
18 print("dragEnterEvent", file=sys.__stderr__)
19 event.acceptProposedAction()
20 return super().dragEnterEvent(event)
21
22 def dragLeaveEvent(self, event):
23 print("dragLeaveEvent", file=sys.__stderr__)
24 return super().dragLeaveEvent(event)
25
26 def dropEvent(self, event):
27 print("dropEvent", file=sys.__stderr__)
28 return super().dropEvent(event)
29
30combo_box = DebuggingQComboBox(window)
31combo_box.setAcceptDrops(True)
32combo_box.setEditable(True)
33#combo_box.lineEdit().setText("initial text")
34layout.addWidget(combo_box)
35window.show() # IMPORTANT!!!!! Windows are hidden by default.
36
37# Start the event loop.
38app.exec()
39