【问题标题】:is pos_hint incompatible with DragBehaviour in Kivy?pos_hint 与 Kivy 中的 DragBehaviour 不兼容吗?
【发布时间】:2017-02-01 12:43:54
【问题描述】:

文档提供了 an example 如何使用 DragBehaviour,只要我使用 pos 来指示小部件的位置,它就可以工作,但如果我使用 pos_hint 则不会:

from kivy.uix.label import Label
from kivy.app import App
from kivy.uix.behaviors import DragBehavior
from kivy.lang import Builder

kv = '''
<DragLabel>:
    # Define the properties for the DragLabel
    drag_rectangle: self.x, self.y, self.width, self.height
    drag_timeout: 10000000
    drag_distance: 0

FloatLayout:
    DragLabel:

        ##################################
        ##### Comment this line and works!
        pos_hint: {'x': 0.5, 'y':0.5}


        size_hint: 0.25, 0.2
        text: 'Drag me'
'''

class DragLabel(DragBehavior, Label):
    pass
class TestApp(App):
    def build(self):
        return Builder.load_string(kv)
TestApp().run()

如何将pos_hintDragBehaviour 一起使用?它们不兼容是因为 Kivy 绑定属性的方式吗?

【问题讨论】:

    标签: python kivy kivy-language


    【解决方案1】:

    根据 Dusty Phillips 的“在 Kivy 中创建应用程序”:

    布局基于pos_hint设置pos;它们不是严格独立的值。 size_hint 也可以这样说,这就是为什么如果你想直接操作 size,布局需要你将 size_hint 显式设置为 None

    换句话说,FloatLayoutDragBehavior 都想设置小部件的pos,因为布局是最后一搏,所以最终获胜。但是FloatLayout基于pos_hint设置pos,如果后者未初始化则不尝试设置。同样,如果您要尝试设置sizeFloatLayout 将使用其默认的size_hint(1,1) 来否决您,除非您首先将size_hint 明确设置为(None,None)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      相关资源
      最近更新 更多