| 1 | from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QComboBox, QVBoxLayout
|
|---|
| 2 |
|
|---|
| 3 | # Only needed for access to command line arguments
|
|---|
| 4 | import 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.
|
|---|
| 9 | app = QApplication(sys.argv)
|
|---|
| 10 |
|
|---|
| 11 | # Create a Qt widget, which will be our window.
|
|---|
| 12 | window = QWidget()
|
|---|
| 13 | layout = QVBoxLayout()
|
|---|
| 14 | window.setLayout(layout)
|
|---|
| 15 | layout.addWidget(QLabel("Test case"))
|
|---|
| 16 | class 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 |
|
|---|
| 30 | combo_box = DebuggingQComboBox(window)
|
|---|
| 31 | combo_box.setAcceptDrops(True)
|
|---|
| 32 | combo_box.setEditable(True)
|
|---|
| 33 | #combo_box.lineEdit().setText("initial text")
|
|---|
| 34 | layout.addWidget(combo_box)
|
|---|
| 35 | window.show() # IMPORTANT!!!!! Windows are hidden by default.
|
|---|
| 36 |
|
|---|
| 37 | # Start the event loop.
|
|---|
| 38 | app.exec()
|
|---|
| 39 |
|
|---|