簡體   English   中英

如何在 pyqt5 中將 QAction 添加到 QLineEdit?

[英]How to add QAction to QLineEdit in pyqt5?

我正在 pyqt5 中創建一個應用程序,其中我必須將 QAction 添加到 QLineEdit。 我嘗試了很多次,但都失敗了。GitHub 問題 這就是我要的
請幫我。 先感謝您

這是一個非常基本的例子:

from PyQt5 import QtWidgets

app = QtWidgets.QApplication([])
# create line edit
line_edit = QtWidgets.QLineEdit()
# create icon. Here I chose a random standard icon but you can create your own from one or more images.
icon = app.style().standardIcon(QtWidgets.QStyle.SP_ArrowRight)
# add action to line edit
action = line_edit.addAction(icon, line_edit.TrailingPosition)
# connect action.triggered signal to a slot
action.triggered.connect(lambda: print('action triggered:', line_edit.text()))
# show line edit and start event loop
line_edit.show()
app.exec()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM