无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

氣輕PyQt6 32 表-背景顏色文字顏色

2023-06-05 08:06 作者:氣輕  | 我要投稿

?

單元背景顏色和文字顏色的處理執(zhí)行后都無法立刻顯示,update(),viewport().update()以及repaint()等處理都試過,但都沒效果。

?

from PyQt6.QtWidgets import *

from PyQt6.QtGui import QBrush,QColor,QFont

import sys

?

treat = ['背景顏色','文字顏色']

class PyQt632(QWidget):

??? def __init__(self):

??????? super().__init__()

??????? self.initUI()

??? def initUI(self):

??????? self.setWindowTitle('氣輕PyQt6')??????????????? # 設(shè)置窗口標(biāo)題

??????? self.resize(490, 300)?????????????? ????????????# 設(shè)置窗口大小

??????? self.setStyleSheet('background-color:#FFC1C1')

?

??????? self.bgColor = QPushButton(treat[0], self)

??????? self.bgColor.setGeometry(10, 120, 80, 30)

??????? self.bgColor.setStyleSheet('background-color:#F5DEB3;color : #8B8682; \

??????????????????? font: bold large /"SimSun/";font-size:16px')

??????? self.bgColor.clicked.connect(lambda :self.buttonClicked(self.bgColor))

?

??????? self.textColor = QPushButton(treat[1], self)

??????? self.textColor.setGeometry(10, 150, 80, 30)

??? ????self.textColor.setStyleSheet('background-color:#F5DEB3;color : #8B8682; \

??????????????????? font: bold large /"SimSun/";font-size:16px')

??????? self.textColor.clicked.connect(lambda :self.buttonClicked(self.textColor))

?

??????? titles = ['編號', ' 第一列 ', ' 第二列 ', ' 第三列 ', ' 第四列 ']

??????? self.table = QTableWidget(8,5,self)???????????? # 創(chuàng)n行m列建空表格

??????? self.table.setGeometry(100, 60,380,200)???????? # 設(shè)置位置和大小

??????? self.table.setStyleSheet('background-color:#E6E6FA;color : #696969; \

???????????? ???????font: bold italic large /"Times New Roman/";font-size:16px')

??????? self.table.setHorizontalHeaderLabels(titles)??? # 水平標(biāo)題

??????? vtitle = list(map(str, list(range(8))))

??????? self.table.setVerticalHeaderLabels(vtitle)????? # 垂直標(biāo)題

????????????? ??????????????????????????????????????????# 自動調(diào)整列寬

??????? self.table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents)

?

??????? self.table.setAlternatingRowColors(True)??????? # 行自動變色

??????? self.table.setFont(QFont("宋體",20))

?

??????? item=QTableWidgetItem('氣輕')

??????? self.table.setItem(0,0, item)

???????

??????? item=QTableWidgetItem('氣輕python')

??????? self.table.setItem(2,0, item)

???????

??????? item=QTableWidgetItem('氣輕PyQt6')

??????? self.table.setItem(4,0, item)

???????

??????? self.show()

?

??? def buttonClicked(self,b):

??????? action = b.text()

??????? rno = self.table.currentRow()

??????? cno = self.table.currentColumn()

?

??????? if rno == -1 or? cno== -1:????????????????????? # 無效位置?

??????????? reply = QMessageBox()

??????????? reply.setText('請選擇有效位置')

??????????? reply.setStandardButtons(QMessageBox.StandardButton.Yes)

??????????? x = reply.exec()

??????????? return

?

??????? reply = QMessageBox()

?

??????? col = QColorDialog.getColor()

?

??????? if not col.isValid():

??????????? reply = QMessageBox()

??????????? reply.setText('請選擇有效顏色')

??????????? reply.setStandardButtons(QMessageBox.StandardButton.Yes)

??????????? x = reply.exec()

??????????? return

?

??????? func = [self.table.item(rno,cno).setBackground,

??????????????? self.table.item(rno,cno).setForeground]

??????? fdict = dict(zip(treat,func))

??????? fdict[action](QBrush(QColor(col.name())))

?

if __name__ == '__main__':

??? app = QApplication(sys.argv)

??? window = PyQt632()

??? sys.exit(app.exec())

?

執(zhí)行結(jié)果


氣輕PyQt6 32 表-背景顏色文字顏色的評論 (共 條)

分享到微博請遵守國家法律
岢岚县| 内黄县| 囊谦县| 盐源县| 汾阳市| 定日县| 章丘市| 北碚区| 沙雅县| 九台市| 广水市| 当雄县| 永城市| 石泉县| 三都| 朝阳区| 黎城县| 鞍山市| 湄潭县| 个旧市| 马龙县| 锦屏县| 夏河县| 高台县| 达州市| 沙洋县| 姚安县| 称多县| 前郭尔| 加查县| 云阳县| 巨野县| 来凤县| 宜兴市| 崇仁县| 苏尼特左旗| 沽源县| 德保县| 文成县| 广河县| 莱阳市|