问题
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