为什么鼠标悬停动画忽略了Gtk3中的转换时间和函数?

时间:2022-11-05 23:02:16

With the new gtk, it is possible to create graphical themes with a file in something like css.

使用新的gtk,可以使用css之类的文件创建图形主题。

Given this css file (named my-gtk-widgets.css):

给定这个css文件(命名为my-gtk-widgets.css):

.button {
    border-radius: 0;
    border-style: solid;
}

.button:hover {
    transition: 3000ms linear;
    border-radius: 50;
}

And the following python code:

以及下面的python代码:

from gi.repository import Gtk
from gi.repository import Gdk

def _destroy_cb(widget, data=None):
    Gtk.main_quit()

window = Gtk.Window()
window.connect("destroy", _destroy_cb)

screen = Gdk.Screen.get_default()

css_provider = Gtk.CssProvider()
css_provider.load_from_path('my-gtk-widgets.css')

context = Gtk.StyleContext()
context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)

box = Gtk.VBox()
window.add(box)

button = Gtk.Button('go-next')
box.pack_start(button, False, False, 0)

window.show_all()
Gtk.main()

Running this code gives a button which changes the border-radius when hovered. But the transition is instant, not animated.

运行这段代码时,会给出一个按钮,该按钮在盘旋时改变边界半径。但这种转变是即时的,而不是动态的。

为什么鼠标悬停动画忽略了Gtk3中的转换时间和函数?

为什么鼠标悬停动画忽略了Gtk3中的转换时间和函数?

What is the reason for this? Do I need a different version of gtk, python, ... ? Or does this animation depend on the gtk theme (in my case the Ubuntu default Ambience)? Or is there something wrong in my css file?

原因是什么?我需要不同版本的gtk, python,…吗?或者这个动画是否依赖于gtk主题(在我的例子中是Ubuntu默认环境)?或者我的css文件有问题吗?

python version: 2.7.2+

python版本:2.7.2 +

gtk version: 3.0

gtk版本:3.0

EDIT: the example is a modified version of this

编辑:这个例子是修改后的版本

2 个解决方案

#1


6  

I am no expert in css, but it appears that you are trying to apply transition on a property on which transition/animation cannot be applied (From this list it appears transition on border-radius is not supported) You could try something like background-color to see the transition effects in the button in you application (Colour change transition could be seen - Gtk-3.0, python-2.7.1, FC15)

在css我不是专家,但似乎你想应用过渡过渡/动画不能应用的一个属性(从这个列表看起来过渡圆角边框不支持)你可以试试类似background看到按钮在您的应用程序的转换效果(颜色变化过渡可以看到- gtk - 3.0,python-2.7.1,FC15)

.button {
    background-color: #00ffff;
    border-style: solid;
}

.button:hover {
    transition: 1s linear;
    background-color: #00ff00;
}

Hope this helps!

希望这可以帮助!

#2


-1  

Put the transition on .button not .button:hover

将转换设置为.button而不是.button:悬浮

#1


6  

I am no expert in css, but it appears that you are trying to apply transition on a property on which transition/animation cannot be applied (From this list it appears transition on border-radius is not supported) You could try something like background-color to see the transition effects in the button in you application (Colour change transition could be seen - Gtk-3.0, python-2.7.1, FC15)

在css我不是专家,但似乎你想应用过渡过渡/动画不能应用的一个属性(从这个列表看起来过渡圆角边框不支持)你可以试试类似background看到按钮在您的应用程序的转换效果(颜色变化过渡可以看到- gtk - 3.0,python-2.7.1,FC15)

.button {
    background-color: #00ffff;
    border-style: solid;
}

.button:hover {
    transition: 1s linear;
    background-color: #00ff00;
}

Hope this helps!

希望这可以帮助!

#2


-1  

Put the transition on .button not .button:hover

将转换设置为.button而不是.button:悬浮