Qt笔记-QScrollBar- qss

//QSS
{
strStyle.append(” QScrollBar:horizontal{ “);
strStyle.append(” max-height:21px; “);
strStyle.append(” min-height:21px; “);
strStyle.append(” border-top:1px solid rgba(0,0,0,50); “);
strStyle.append(” border-bottom:1px solid rgba(0,0,0,50); “);
strStyle.append(” margin:0px,0px,0px,0px; “);
strStyle.append(” padding-left:27px; “);
strStyle.append(” padding-right:27px; “);
strStyle.append(” background-color: rgb(255, 255, 255); “);
strStyle.append(” } “);
strStyle.append(” QScrollBar::handle:horizontal{ “);
strStyle.append(” height:21px; “);
strStyle.append(” min-width:120; “);
strStyle.append(” background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255),stop:0.048 rgba(255,255, 255, 255), stop:0.05 rgba(248,248, 248, 255), stop:1 rgba(238, 238, 238, 255),); “);
strStyle.append(” border-left:1px solid rgba(0,0,0,50); “);
strStyle.append(” border-right:1px solid rgba(0,0,0,50); “);
strStyle.append(” } “);
strStyle.append(” QScrollBar::sub-line:horizontal{ “);
strStyle.append(” margin:0px,0px,0px,0px; “);
strStyle.append(” width:27px; “);
strStyle.append(” subcontrol-position:left bottom; “);
strStyle.append(” background: url(:/image/ScrollBarHorLeft.png) no-repeat; “);
strStyle.append(” } “);
strStyle.append(” QScrollBar::add-line:horizontal{ “);
strStyle.append(” margin:0px,0px,0px,0px; width:27px; “);
strStyle.append(” border-left:0px solid rgba(0,0,0,50); “);
strStyle.append(” border-right:0px solid rgba(0,0,0,50); “);
strStyle.append(” border-top:0px solid rgba(0,0,0,50); “);
strStyle.append(” border-bottom:0px solid rgba(0,0,0,50); “);
strStyle.append(” background:url(:/image/ScrollBarHorRight.png) no-repeat; “);
strStyle.append(” subcontrol-position:right bottom; “);
strStyle.append(” } “);
}

//除了设QSS外,还需要做下面的一些设置,以保证效果能生效
//方法1:
//备注:如果出来的效果不行,则需要使用一个QWidget包一下
QString parentStyle = ((QWidget *)p->parent())->styleSheet();
((QWidget *)p->parent())->setStyleSheet(“”);
p->setStyleSheet( p->styleSheet() + strStyle );
((QWidget *)p->parent())->setStyleSheet(parentStyle);

//方法二:
//备注:在没有QLayout下使用,没有问题,如果需要使用,则使用方法1
QObject *oldParent = p->parent();
if ( oldParent->inherits(“QWidget”) )
{
QWidget w;
p->setParent(&w);
p->setStyleSheet( p->styleSheet() + strStyle );
p->setParent((QWidget *) oldParent);
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值