在下图中,我有一个 QTableWidget 来查看来自一对多关系 SQLite 数据库的数据,我设法使用 setspan 功能和 @eyllanesc 的这个答案的帮助来合并一些列输出以正确显示数据。
我现在想要实现的是用背景颜色(交替颜色)对每个订单进行着色以提高可读性,尝试了 table.setAlternatingRowColors(True) 但当订单包含多个项目时它会失败!如何完成条件行样式?
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
query_result = [(683, 18, 765, 1.73, '1 ring ruby ring', 685.71, 'vincent percy', 'john joseph croft'), (684, 14, 900, 4.48, '1 earring ear drop', 534.86, 'Ben Otten', 'Anne Cooksley Beltrame'), (684, 14, 900, 2.1, '1 ring cluster ring', 534.86, 'Ben Otten', 'Anne Cooksley Beltrame'), (684, 18, 900, 1.3, '1 ring eternity band', 685.71, 'Ben Otten', 'Anne Cooksley Beltrame'), (685, 14, 200, 3.26, '1 ring promise ring', 534.86, 'raymond bob', 'owen george taylor'), (686, 24, 450, 10.0, '1 bullion Gold bar', 914.28, 'vincent percy', 'owen george taylor'), (687, 14, 345, 4.75, '1 earring Dangles Earring', 534.86, 'Ben Otten', 'dan justin balmers'), (688, 18, 810, 3.1, '1 earring fish hookEarring', 677.14, 'raymond bob', 'jeff david steve'), (688, 21, 810, 2.6, '1 ring ANTIQUE RING', 790, 'raymond bob', 'jeff david steve')]
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("mini_ui")
self.setGeometry(300, 150, 800, 600)
self.Ui()
def Ui(self):
vbox = QVBoxLayout()
btn_show_table = QPushButton("view sample data")
btn_show_table.clicked.connect(self.today_sales_table)
self.viewTodayTable = QTableWidget()
self.viewTodayTable.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.viewTodayTable.setObjectName("viewTodayTable")
self.viewTodayTable.setColumnCount(8)
self.viewTodayTable.setRowCount(0)
临摹微笑
相关分类