你永远也无法预料到,Qt到底埋了多少坑(我的是PyQt5),
一个破文本居中都要搞那么麻烦
一堆样式这里不生效那里不生效的真的是离谱
代码+运行结果:
import sys
from PyQt5.QtWidgets import QApplication,QComboBox
from PyQt5.QtWidgets import QStyle,QStylePainter,QStyleOptionComboBox,QStyleOptionButton
from PyQt5.QtGui import QPalette,QPainter
from PyQt5.QtCore import Qt
__all__=['XJQ_ComboBox']
class XJQ_ComboBox(QComboBox):
cbStyle='''
QComboBox{
font-size:20px;
background:rgba(96,192,255,192);
border-radius:10px;
min-width:50px;
text-align:center;
}
QComboBox::drop-down{
width:0;
image:none;
}
QComboBox QAbstractItemView {
font-size:25px;
min-width: 50px;
font-weight:0;
font-family:serif;
background-color: rgba(224, 224, 128, 255);
}
QComboBox QAbstractItemView::item {
height: 30px;
background-color: rgba(237, 0, 0,128);
}
QComboBox QScrollBar
{
background: rgba(255,255,255,5%);
width: 5px;
}
QComboBox QScrollBar::add-line {
width:0;
height:0;
}
QComboBox QScrollBar::sub-line {
width:0;
height:0;
}
QComboBox QScrollBar::handle {
background: rgba(64,64,64,75%);
}
QComboBox QScrollBar::sub-page {
background: rgba(0,0,0,30%);
}
QComboBox QScrollBar::add-page {
background: rgba(0,0,0,30%);
}
'''
def __init__(self,*args):
super().__init__(*args)

本文讲述了在PyQt5中实现QComboBox文字居中的困难与解决方法,包括样式表生效问题和代码调整,同时提供了多个参考资料链接。

416

被折叠的 条评论
为什么被折叠?



