aboutsummaryrefslogtreecommitdiffstats
path: root/examples/network/googlesuggest/searchbox.py
diff options
context:
space:
mode:
authorjaime02 <gemailpersonal02@gmail.com>2022-02-15 12:10:46 +0100
committerCristián Maureira-Fredes <cristian.maureira-fredes@qt.io>2022-06-02 06:43:22 +0200
commit0a187a3aa58d326349d6c3415a031f0f68fdb84a (patch)
tree8ee9ccf697563b53082e7eab7d1d53c742538888 /examples/network/googlesuggest/searchbox.py
parentdc06e881f72f2added3b7211a78e2ec15065a623 (diff)
example: add google suggest
Ported from C++ Task-number: PYSIDE-841 Pick-to: 6.2 6.3 Change-Id: Ib64218925961f3d0bbd783c5bb9d8365a81e8767 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'examples/network/googlesuggest/searchbox.py')
-rw-r--r--examples/network/googlesuggest/searchbox.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/network/googlesuggest/searchbox.py b/examples/network/googlesuggest/searchbox.py
new file mode 100644
index 000000000..9cbe20b23
--- /dev/null
+++ b/examples/network/googlesuggest/searchbox.py
@@ -0,0 +1,27 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+from PySide6.QtCore import Slot
+from PySide6.QtGui import QDesktopServices
+from PySide6.QtWidgets import QLineEdit
+
+from googlesuggest import GSuggestCompletion
+
+
+class SearchBox(QLineEdit):
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self.completer = GSuggestCompletion(self)
+
+ self.returnPressed.connect(self.do_search)
+ self.setWindowTitle("Search with Google")
+
+ self.adjustSize()
+ self.resize(400, self.height())
+ self.setFocus()
+
+ @Slot()
+ def do_search(self):
+ self.completer.prevent_suggest()
+ url = f"https://www.google.com/search?q={self.text()}"
+ QDesktopServices.openUrl(url)