PYQT下框线比文字小的显示方法
1.效果如下图所示

2.代码详情
from PyQt5.Qt import *
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("")
self.resize(600, 500)
label1 = QLabel('外边距和内边距设置', self)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
qApp.setStyleSheet("""
QLabel{
border-bottom-width:10px;
padding:5px 30px;}
QLabel:hover{
border-bottom-width:10px;
border-color:qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,
stop:0 rgba(0, 0, 255, 0), stop:0.33 rgba(0, 0, 0, 0),
stop:0.34 rgba(255, 30, 30, 255), stop:0.66 rgba(255, 0, 0, 255),
stop:0.67 rgba(255, 255, 0, 0), stop:1 rgba(255, 255, 0, 0));
border-style:solid;
padding:5px 30px;}
""")
window.show()
sys.exit(app.exec_())
3.实现逻辑
使用的渐变色,在两边加了两道透明的渐变颜色就可以做到
使用PYQT设置QLabel边框渐变效果,
该文章展示了如何在PYQT中创建一个QLabel,通过调整边框宽度、内边距和应用渐变色,使得边框在文字下方形成一种比文字小的视觉效果。代码示例详细解释了实现这一效果的逻辑,特别是利用透明渐变色在边框两侧创造独特的显示样式。
1万+

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



