问题描述
我想要一个 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 中悬停/按下时设置按钮图像大小的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!