Issue
I am making an application in pyqt5 in which I have to add QAction to QLineEdit. I have tried many times but failed.
This is what I want
Please help me. Thank you in advance
Solution
Here is a very basic example:
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()
Answered By - Heike
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.