如何使用QLineEdit创建搜索栏,我在想,如果您在任何软件中都按“ ctrl F”,它会突出显示在搜索栏中键入的文本,或者我要创建像= {“面包”:面包,“牛奶”:牛奶,“样品”:样品}?稍后,我尝试使用表创建数据库并插入-SQLite3。
这是代码:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(902, 794)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(0, 0, 901, 771))
self.tableWidget.setRowCount(100)
self.tableWidget.setColumnCount(4)
self.tableWidget.setObjectName("tableWidget")
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
font = QtGui.QFont()
font.setFamily("Script MT Bold")
font.setPointSize(12)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
font.setStrikeOut(False)
font.setKerning(True)
item.setFont(font)
self.tableWidget.setItem(0, 0, item)
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
font = QtGui.QFont()
font.setFamily("Script MT Bold")
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
self.tableWidget.setItem(0, 1, item)
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
font = QtGui.QFont()
font.setFamily("Script MT Bold")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
self.tableWidget.setItem(0, 2, item)
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
font = QtGui.QFont()
font.setFamily("Script MT Bold")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
item.setFont(font)
self.tableWidget.setItem(0, 3, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setItem(1, 0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setItem(1, 1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setItem(1, 2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setItem(1, 3, item)
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
self.tableWidget.setItem(2, 1, item)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(650, 189, 137, 22))
self.lineEdit.setObjectName("lineEdit")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(571, 181, 72, 33))
font = QtGui.QFont()
font.setFamily("Script MT Bold")
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(570, 30, 261, 131))
font = QtGui.QFont()
font.setFamily("Script MT Bold")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.textBrowser.setFont(font)
self.textBrowser.setObjectName("textBrowser")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(600, 710, 101, 41))
font = QtGui.QFont()
font.setFamily("Script MT Bold")
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.tableWidget.raise_()
self.label.raise_()
self.lineEdit.raise_()
self.textBrowser.raise_()
self.pushButton.raise_()
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
__sortingEnabled = self.tableWidget.isSortingEnabled()
self.tableWidget.setSortingEnabled(False)
item = self.tableWidget.item(0, 0)
item.setText(_translate("MainWindow", "Item Name"))
item = self.tableWidget.item(0, 1)
item.setText(_translate("MainWindow", "Number of Stocks"))
item = self.tableWidget.item(0, 2)
item.setText(_translate("MainWindow", "mSRP"))
item = self.tableWidget.item(0, 3)
item.setText(_translate("MainWindow", "SRP"))
item = self.tableWidget.item(1, 0)
item.setText(_translate("MainWindow", "Bread"))
item = self.tableWidget.item(1, 1)
item.setText(_translate("MainWindow", "5"))
item = self.tableWidget.item(1, 2)
item.setText(_translate("MainWindow", "5 pesos"))
item = self.tableWidget.item(1, 3)
item.setText(_translate("MainWindow", "7 pesos"))
self.tableWidget.setSortingEnabled(__sortingEnabled)
self.label.setText(_translate("MainWindow", "Search"))
self.textBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Script MT Bold\'; font-size:12pt; font-weight:600; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:18pt;\">Automated System Inventory</span></p></body></html>"))
self.pushButton.setText(_translate("MainWindow", "SAVE"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())