我想看到工具提示Qt当鼠标指针悬停在图标上时操作栏.
是的,我可以使用mode='spinner'
,但图标更好。
您可以改进和扩展的一个简单示例:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.uix.actionbar import ActionButton
from kivy.uix.label import Label
from kivy.clock import Clock
Builder.load_string("""
<Tooltip>:
size_hint: None, None
size: self.texture_size[0]+5, self.texture_size[1]+5
canvas.before:
Color:
rgb: 0.2, 0.2, 0.2
Rectangle:
size: self.size
pos: self.pos
<MyWidget>
ActionBar:
ActionView:
MyActionButton:
icon: 'atlas://data/images/defaulttheme/audio-volume-high'
MyActionButton:
icon: 'atlas://data/images/defaulttheme/audio-volume-high'
""")
class Tooltip(Label):
pass
class MyActionButton(ActionButton):
tooltip = Tooltip(text='Hello world')
def __init__(self, **kwargs):
Window.bind(mouse_pos=self.on_mouse_pos)
super(ActionButton, self).__init__(**kwargs)
def on_mouse_pos(self, *args):
if not self.get_root_window():
return
pos = args[1]
self.tooltip.pos = pos
Clock.unschedule(self.display_tooltip) # cancel scheduled event since I moved the cursor
self.close_tooltip() # close if it's opened
if self.collide_point(*self.to_widget(*pos)):
Clock.schedule_once(self.display_tooltip, 1)
def close_tooltip(self, *args):
Window.remove_widget(self.tooltip)
def display_tooltip(self, *args):
Window.add_widget(self.tooltip)
class MyWidget(Widget):
pass
class ClientApp(App):
def build(self):
return MyWidget()
if __name__ == '__main__':
ClientApp().run()
首先我绑定on_mouse_pos
方法Window.mouse_pos
事件,以便我可以检测鼠标光标何时悬停在我的子类上ActionButton
。这是基于这个片段。然后我安排一个动作Clock.schedule_once()
如果我不移动光标,则使我的工具箱可见。为了显示,我只是将 Label 的子类添加到小部件堆栈中。您可以更换display_tooltip()
and close_tooltip()
方法与更复杂的方法。
编辑:相应更新代码这个答案
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)