|
# A demo of how to get notifications that text in a QLineEdit
# has been edited.
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class Demo_QLineEdit(QDialog):
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.setWindowTitle("Demo QLineEdit")
self.setFixedSize(400, 200)
# Create the main vertical layout.
vlayout = QVBoxLayout()
self.setLayout(vlayout)
self.addLineEditPanel(vlayout)
# Ensure the LineEditPanel is pushed to the upper edge of the
# Dialog window.
vlayout.addStretch()
self.show()
#--------------------------------------------------------------------
def addLineEditPanel(self, parentLayout):
self.textLine = QLineEdit()
self.textLine.textChanged[str].connect(self.lineChangedAction)
parentLayout.addWidget(self.textLine)
#--------------------------------------------------------------------
# Activated by the text in the QLineEdit being edited.
def lineChangedAction(self, text):
print(text)
#--------------------------------------------------------------------
# ========================================================
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
demo = Demo_QLineEdit() # <<-- Create an instance
demo.show()
sys.exit(app.exec_())
|