如何使用 CSS 在 Qt4 中悬停/按下时设置按钮图像大小的样式 [英] How to style PushButton's image size on hover/pressed in Qt4 using CSS

查看:40
本文介绍了如何使用 CSS 在 Qt4 中悬停/按下时设置按钮图像大小的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个 QPushButton,其中图像在鼠标悬停时调整大小.

I want to have a QPushButton where the image resizes on hovering with the mouse.

以下适用于 QToolButton:

The following works for QToolButton:

QToolButton
{
    border: 0px;
}

QToolButton:hover
{
    padding: 2px;
}

QToolButton:pressed
{
    padding: 4px;
}

...图像被调整大小(因为填充改变了).

... the image gets resized (because padding changed).

但是当将其应用于 QPushButton 时,它会失败(图像不会调整大小).

But when applying this to a QPushButton, it fails (image does not resize).

我也是这样做的:

QPushButton
{
    border: 0px;
}

QPushButton:hover
{
    padding: 2px;
}

QPushButton:pressed
{
    padding: 4px;
}

当边框增加(而不是 0)并且设置了边距而不是填充时,您可以看到应用于边框的调整大小效果......但图像被忽略.如何解决这个问题?

When the border is increased (instead of 0) and a margin is set instead of padding you can see the resize effect applyed to the border... but the image is ignored. How to solve this?

推荐答案

据我所知,:hover 修饰符不处理 QPushButton 属性的动态变化.所以使用 QToolButton 是个好主意.例如,QPushButton 的文本修饰(斜体/下划线)不能更改,但可以为 QToolButton 更改.这就是为什么我们使用 QToolButton 自定义而不是编写自己的小部件来显示 URL.

As I know, :hover modificator does not process dynamic changes of properties for QPushButton. So using of QToolButton is good idea. For example, text decoration (italic/underline) couldnt be changed for QPushButton, but could be changed for QToolButton. Thats why we use QToolButton customization instead of writing own widgets for displaying URLs.

这篇关于如何使用 CSS 在 Qt4 中悬停/按下时设置按钮图像大小的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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