How to style PushButton's image size on hover/pressed in Qt4 using CSS

拥有回忆 提交于 2019-12-12 00:44:46

问题


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

The following works for QToolButton:

QToolButton
{
    border: 0px;
}

QToolButton:hover
{
    padding: 2px;
}

QToolButton:pressed
{
    padding: 4px;
}

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

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

I did it the same way:

QPushButton
{
    border: 0px;
}

QPushButton:hover
{
    padding: 2px;
}

QPushButton:pressed
{
    padding: 4px;
}

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?


回答1:


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.



来源:https://stackoverflow.com/questions/18250591/how-to-style-pushbuttons-image-size-on-hover-pressed-in-qt4-using-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!