Qt使用StyleSheet悬停时加宽QScrollBar [英] qt widen QScrollBar when hover using StyleSheet

查看:568
本文介绍了Qt使用StyleSheet悬停时加宽QScrollBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自定义样式表更改垂直QScrollBar的宽度

I'm trying to change the width of a vertical QScrollBar with a custom stylesheet like

QScrollBar:vertical 
{
     border: 2px solid grey;
     background: #32CC99;
     width: 10px;
     margin: 22px 0 22px 0;"
}
QScrollBar:vertical:hover { 
     background: red; 
     width: 25px ;
}

它不起作用.我有没有做错什么?我们不能在运行时更改小部件的宽度吗?

It doesn't work. Did I make any mistake? Can't we change the width of widget in run-time?

推荐答案

我认为没有办法通过单独使用样式表来做到这一点.

I don't think there is a way of doing this by using the stylesheets alone.

您可以创建自己的滚动条并覆盖 enterEvent leaveEvent 并在那里更改样式表.

You could create your own scrollbar and override the enterEvent and leaveEvent and change the stylesheet there.

您还可以在现有的滚动条上安装事件过滤器(您可以使用 QAbstractScrollArea::verticalScrollBar() 函数)并侦听相同的事件并在那里更改样式表.

You could also install an event filter to your existing scrollbar (you can get your scrollbar by using the QAbstractScrollArea::verticalScrollBar() function) and listen to the same events and change the stylesheet there.

这篇关于Qt使用StyleSheet悬停时加宽QScrollBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆