早晨/下午/晚上
我以前遇到过砖墙,我能够使用QLineEdit来为您提供自动填充选项,例如:
Autofill(无法嵌入图像,因此无法链接)
以前,这些值是在列表中排序的,并且可以使用QCompleter和QStringListModel来实现。
已将所有QLineEdits的表单移至现在的QTableWidget。我想通过QLineEdit达到与以前相同的效果,如果在字段中键入带有标签的“配件”,它将与以前一样执行。以前存储在列表中的值现在在SQL DB中。
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtSql import *
import tkinter
import sqlite3
import sys
connection = sqlite3.connect("PriceList.db")
# Getting Screen info
root = tkinter.Tk()
root.withdraw()
def setup(uname):
global user
user = uname
# Layout
layout = QHBoxLayout()
right_side = QGridLayout()
right_side.setAlignment(Qt.AlignTop)
left_side = QVBoxLayout()
class QuotesWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(QuotesWindow, self).__init__(*args, **kwargs)
# Window Settings
self.setWindowTitle("Herpy - " + user)
self.setWindowIcon(QIcon("icon.png"))
self.showMaximized()
# Right Side Enter Quote
self.input_table()
right_side.addWidget(self.tableWidget)
# Mid Line
mid_line = QFrame()
mid_line.setFrameShape(QFrame.VLine)
mid_line.setFrameShadow(QFrame.Sunken)
# Left Side Details
acc_bt = QPushButton("Account")
left_side.addWidget(acc_bt)
# Who
who_box = QLineEdit()
who_box.setPlaceholderText("Name")
left_side.addWidget(who_box)
# Street
street_box = QLineEdit()
street_box.setPlaceholderText("Street")
left_side.addWidget(street_box)
# Town
town_box = QLineEdit()
town_box.setPlaceholderText("Town")
left_side.addWidget(town_box)
# County
county_box = QLineEdit()
county_box.setPlaceholderText("County")
left_side.addWidget(county_box)
# Postcode
postc_box = QLineEdit()
postc_box.setPlaceholderText("Postcode")
left_side.addWidget(postc_box)
# Telephone
telep_box = QLineEdit()
telep_box.setPlaceholderText("Telephone Number")
left_side.addWidget(telep_box)
# Seperator
left_line = QFrame()
left_line.setFrameShape(QFrame.HLine)
left_line.setFrameShadow(QFrame.Sunken)
left_side.addWidget(left_line)
# Author
q_author = QLineEdit()
q_author.setPlaceholderText(user)
q_author.setReadOnly(True)
left_side.addWidget(q_author)
# Placed By
placed_b = QLineEdit()
placed_b.setPlaceholderText("Placed By")
left_side.addWidget(placed_b)
# Placed With
placed_w = QLineEdit()
placed_w.setPlaceholderText("Placed With")
left_side.addWidget(placed_w)
# Reference
ref_input = QLineEdit()
ref_input.setPlaceholderText("Reference")
left_side.addWidget(ref_input)
# To Fill Space
left_side.addStretch(1)
# Layouts
layout.addLayout(left_side)
layout.addWidget(mid_line)
layout.addLayout(right_side)
# Shortcut
shortcut = QShortcut(QKeySequence("Shift+Return"), self)
#shortcut.activated.connect(self.new_input)
# Makes it fucking render
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
self.show()
def input_table(self):
# Auto Fill for Fittings
model = QSqlTableModel()
model.select()
completer = QCompleter()
completer.setCompletionColumn(1)
#completer.setCaseSensitivity(CaseInsensitive)
#completer.setCompletionRole(QtCore.Qt.EditRole)
#Create table
headers = ["Fittings", "Quantity", "Price", "Total"]
self.tableWidget = QTableWidget()
self.tableWidget.setRowCount(50)
self.tableWidget.setColumnCount(4)
self.tableWidget.setItem(0,0, QTableWidgetItem("Cell (1,1)"))
self.tableWidget.move(0,0)
self.tableWidget.setColumnWidth(1, 80)
self.tableWidget.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
#self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
#self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.tableWidget.setHorizontalHeaderLabels(headers)
预先感谢:)对不起,有点混乱
编辑:被标记为欺骗并给予sqlite3 table into QTableWidget, sqlite3, PyQt5 无法看到它与我的代码的对应关系,我丢失了什么吗?
Edit2:更改了文本,使其更加不稳定