From 6a20e318d403dfaf8ad1d7dbe62788cf56f4c2e9 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Wed, 12 Dec 2018 10:07:46 -0500 Subject: [PATCH] New feature - Drag and Drop for Text Input field. Drop a file onto input and get the filename automatically entered --- PySimpleGUIQt/PySimpleGUIQt.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/PySimpleGUIQt/PySimpleGUIQt.py b/PySimpleGUIQt/PySimpleGUIQt.py index b277e2c7..867dd937 100644 --- a/PySimpleGUIQt/PySimpleGUIQt.py +++ b/PySimpleGUIQt/PySimpleGUIQt.py @@ -517,6 +517,17 @@ class InputText(Element): font=font, tooltip=tooltip, visible=visible, size_px=size_px) + def dragEnterEvent(self, e): + if e.mimeData().hasText(): + e.accept() + else: + e.ignore() + + def dropEvent(self, e): + self.QT_QLineEdit.setText(e.mimeData().text()) + + + class InputTextWidget(QWidget): def __init__(self, qt_qlineedit, element): self.QT_QLineEdit = qt_qlineedit @@ -530,8 +541,9 @@ class InputText(Element): return QWidget.eventFilter(self, widget, event) + def QtCallbackFocusInEvent(self,value): - print('Got focus!') + return def QtCallbackTextChanged(self, value): @@ -618,6 +630,8 @@ class Combo(Element): self.QT_ComboBox.addItems(self.Values) + + def Update(self, value=None, values=None, set_to_index=None, disabled=None, readonly=None, background_color=None, text_color=None, font=None, visible=None): if values is not None: self.Values = values @@ -4539,6 +4553,10 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win): default_text = element.DefaultText element.QT_QLineEdit = qlineedit = QLineEdit() + qlineedit.setAcceptDrops(True) + qlineedit.dragEnterEvent = element.dragEnterEvent + qlineedit.dropEvent = element.dropEvent + if element.Justification[0] == 'c': element.QT_QLineEdit.setAlignment(Qt.AlignCenter) elif element.Justification[0] == 'r':