ActionPrevious获得了意外的背景 [英] ActionPrevious getting an unexpected background

查看:104
本文介绍了ActionPrevious获得了意外的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在kv中制定了一个规则,以使Button类具有特定的背景(在图像中提供).当我创建一个包含ActionPreviousActionButton小部件的ActionBar时,它们似乎都具有相同的背景.
而且我会理解ActionButton实例具有该背景,因为它继承自ButtonActionItem类,但是为什么ActionPrevious却具有相同的背景?它从BoxLayoutActionItem继承,这两个都与Button类无关.背后的原因是什么?

I've made a rule in my kv for the Button class to have a specific background (provided in an image). When I created an ActionBar that contains ActionPrevious and ActionButton widgets, they both seemed to get the same background.
And I would understand that ActionButton instance got that background, since it inherits from Button and ActionItem classes, but why did the ActionPrevious get the same background? It inherits from BoxLayout and ActionItem, neither of which have anything to do with the Button class. What's the reason behind it?

还有一个附带问题
ActionPrevious具有属性with_previous,当设置为True时,该属性添加可单击的箭头.但是,小部件的标题仍然不可单击.但是文档说这个属性会使整个窗口小部件都可点击.尽管没什么大不了,但我还是希望整个ActionPrevious小部件背景在印刷时有所变化.有可能实现这一目标吗?
所以我的意思是,当您按下后退"箭头时,只有其周围的空间和应用程序图标变为蓝色,而文本却没有,就好像它是其他小部件的一部分一样.

Also, a side question
The ActionPrevious has a property with_previous which, when set to True, adds a clickable arrow. However, the title of the widget remains unclickable. But the docs say that this property would make the whole widget clickable. While it's not a big deal, I'd rather want the entire ActionPrevious widget background to change on press. Is it possible to achieve this?
So what I mean is that when you press the Back arrow, only the space around it and the app icon turns blue, but the text doesn't, as if it's part of a different widget.

以下是可视化问题的代码:

Here is the code to visualize the question:

from kivy.base import runTouchApp
from kivy.lang import Builder
from kivy.uix.actionbar import ActionBar

Builder.load_string('''
<Button>:
    background_normal: 'some_file.png'

<MenuBar>:
    ActionView:
        ActionPrevious:
            title: "Log out"
            with_previous: True
        ActionButton:
            text: "Settings"
''')
class MenuBar(ActionBar):
    pass

runTouchApp(MenuBar())

推荐答案

好的,事实就在style.kv文件中.基本上,ActionPrevious小部件具有以下结构:

Okay, so the truth was in the style.kv file. Basically, ActionPrevious widget has the following structure:

<ActionPrevious>:
    GridLayout:
        ActionPreviousButton:
            GridLayout:
                ActionPreviousImage:
                    id: prev_icon_image  # the "back" arrow
                ActionPreviousImage:
                    id: app_icon_image   # the app icon
                Widget:
                    # perhaps something to split the title from the GridLayout
    Label:
        id: title                        # the title 

ActionPreviousButton继承自Button,所以这就是ActionPrevious箭头部分获得该背景的原因.

And the ActionPreviousButton inherits from Button, so that's why the ActionPrevious arrow part was getting that background.

这也是副问题的答案.由于可单击部分是ActionPreviousButton,并且标题保留在Label中,而不是其子元素,因此文本不可单击.因此,要解决此问题,必须创建一个自定义类,并将Label放置为ActionPreviousButton的子代.

Here also lies the answer to the side question. Since the clickable part is the ActionPreviousButton, and the title is kept in a Label, that is not a child of it, the text is unclickable. So to fix that, one has to create a custom class and put the Label as a child of the ActionPreviousButton.

这篇关于ActionPrevious获得了意外的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆