From 59d9cc4c189c8fe8700c33abce5e4b6415e8a219 Mon Sep 17 00:00:00 2001
From: kienle <kienle@passcal.nmt.edu>
Date: Fri, 24 Mar 2023 10:35:35 -0600
Subject: [PATCH] Get clear search button from search line edit

---
 sohstationviewer/view/ui/main_ui.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sohstationviewer/view/ui/main_ui.py b/sohstationviewer/view/ui/main_ui.py
index d7babd605..5c2bda0f1 100755
--- a/sohstationviewer/view/ui/main_ui.py
+++ b/sohstationviewer/view/ui/main_ui.py
@@ -399,6 +399,20 @@ class UIMainWindow(object):
         self.search_line_edit.setToolTip('Filter the list of files based on '
                                          'the content.')
         self.search_line_edit.setClearButtonEnabled(True)
+        try:
+            # This value was obtained from the C++ source of QT. We use it here
+            # so that the QAction found is guaranteed to be the clear button.
+            clear_action_name = '_q_qlineeditclearaction'
+            found_actions = self.search_line_edit.findChildren(
+                QAction, clear_action_name
+            )
+            self.clear_search_action = found_actions[0]
+        except IndexError:
+            # If the name of the clear button is changed in the C++ source of
+            # QT, nothing will be found. So, we raise
+            raise ValueError('No clear button could be found. Check its '
+                             'objectName attribute using QObject.findChildren '
+                             'without a name.')
         search_layout.addWidget(self.search_line_edit)
         search_layout.addSpacing(2)
         self.search_button = QPushButton('Search', self.central_widget)
-- 
GitLab