我有一个文本列表,如果用户在 中搜索文本QLineEdit
,我会打印该文本。里面有一个QCompleter
。QLineEdit
问题是,正如我们所知Text
,text
不一样,但对用户来说是一样的。因此,如果用户开始输入Text
或text
,我想将其更改为TEXT
实时QLineEdit
。所以每当用户输入一个字母时,我想把它变成大写QCompleter
- QLineEdit
。我怎样才能做到这一点?我有这个自动取款机;
from PyQt5.QtWidgets import QApplication,QPushButton,QMainWindow,QLabel,QLineEdit,QCompleter
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import QPoint
import sys
class cssden(QMainWindow):
def __init__(self):
super().__init__()
self.mwidget = QMainWindow(self)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
#size
self.setFixedSize(600,400)
#LINE EDIT QCOMPLETER
self.label = QLineEdit(self)
self.label.setGeometry(100,100,300,30)
self.label.setStyleSheet("color: red;"
"font: bold 15pt 'Arial';")
self.t = ["Hello","hi","Hey"]
self.label.setCompleter(QCompleter(self.t, self))
#BUTTON
self.buton = QPushButton(self)
self.buton.setText("Click")
self.buton.setGeometry(200,140,90,50)
self.buton.clicked.connect(self.hangiButon)
#SET LABEL
self.set_label = QLabel(self)
self.set_label.setGeometry(100,300,900,100)
self.set_label.setStyleSheet("color: green;"
"font: bold 18pt 'Times New Roman';")
self.show()
def hangiButon(self):
print(self.label.text(), self.t.index(self.label.text())+1)
self.set_label.setText("Pressed to --> {}.".format(self.label.text().rstrip()))
def mousePressEvent(self, event):
self.oldPos = event.globalPos()
def mouseMoveEvent(self, event):
delta = QPoint (event.globalPos() - self.oldPos)
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldPos = event.globalPos()
app = QApplication(sys.argv)
app.setStyleSheet("QMainWindow{background-color: rgb(30,30,30);border: 2px solid rgb(20,20,20)}")
ex = cssden()
sys.exit(app.exec_())
所以如果我按下h
我想看到所有的词,不仅hi
而且我想h
立即改变它。但无法弄清楚如何。