Qt常用样式表-滚动条QScrollBar

13 篇文章 0 订阅

滚动条QScrollBar

QScrollBar:horizontal

{

background:transparent;

border:none;

height:12px;

}

QScrollBar::handle:horizontal

{

background:#C4C4C4;

border:none;

border-radius:4px;

height:8px;

min-width:20px;

margin:2px;

}

QScrollBar::handle:horizontal:hover

{

background:#C4C4C4;

}

QScrollBar:vertical

{

background:transparent;

border:none;

width:12px;

}

QScrollBar::handle:vertical

{

background:#C4C4C4;

border:none;

border-radius:4px;

width:8px;

min-height:20px;

margin:2px;

}

QScrollBar::handle:vertical:hover

{

background:#C4C4C4;

}

QScrollBar::add-page:horizontal,QScrollBar::sub-page:horizontal

{

background:rgba(255,255,255,10);

}

QScrollBar::add-line:horizontal,QScrollBar::sub-line:horizontal

{

background:transparent;

}

QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical

{

background:rgba(255,255,255,10);

}

QScrollBar::add-line:vertical,QScrollBar::sub-line:vertical

{

background:transparent;

}

可以通过样式表来设置QTextBrowser的水平滚动条样式。以下是一个示例: ```python from PyQt5.QtWidgets import QApplication, QTextBrowser from PyQt5.QtCore import Qt app = QApplication([]) text_browser = QTextBrowser() # 设置样式表 style_sheet = """ QTextBrowser { background-color: #f0f0f0; color: #333; font-size: 14px; } QScrollBar:horizontal { border: none; background: #f0f0f0; height: 10px; margin: 0px 20px 0 20px; } QScrollBar::handle:horizontal { background: #c0c0c0; min-width: 20px; } QScrollBar::add-line:horizontal { border: none; background: #f0f0f0; width: 20px; subcontrol-position: right; subcontrol-origin: margin; } QScrollBar::sub-line:horizontal { border: none; background: #f0f0f0; width: 20px; subcontrol-position: left; subcontrol-origin: margin; } """ text_browser.setStyleSheet(style_sheet) text_browser.setPlainText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fringilla ex eu libero auctor, a suscipit purus lacinia. Quisque vel purus odio. Sed in dui consectetur, vestibulum massa a, bibendum mauris. Duis euismod mauris a lectus vehicula, in faucibus justo pellentesque. Vestibulum posuere risus sit amet neque bibendum, id lacinia ipsum venenatis. Praesent commodo, lorem at bibendum tristique, eros urna vulputate augue, eget lacinia nisi purus a tellus. Donec pulvinar lectus ac consequat congue. Nullam rutrum dolor vel massa bibendum, id lacinia lacus fermentum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut faucibus velit quis metus tincidunt, sit amet malesuada magna bibendum. Fusce nec eros eget leo suscipit bibendum. Nunc eget magna euismod, tempor sapien eget, commodo dolor. ") text_browser.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) text_browser.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) text_browser.show() app.exec_() ``` 这个样式表QTextBrowser的背景色设置为灰色,文本颜色设置为深灰色,字体大小设置为14px。水平滚动条的高度设置为10px,滑块的最小宽度设置为20px,滑块的背景色设置为浅灰色。增加按钮和减少按钮的宽度都设置为20px,背景色都设置为浅灰色。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值