ActionPrevious获得了意外的背景 [英] ActionPrevious getting an unexpected background
问题描述
我在kv中制定了一个规则,以使Button
类具有特定的背景(在图像中提供).当我创建一个包含ActionPrevious
和ActionButton
小部件的ActionBar
时,它们似乎都具有相同的背景.
而且我会理解ActionButton
实例具有该背景,因为它继承自Button
和ActionItem
类,但是为什么ActionPrevious
却具有相同的背景?它从BoxLayout
和ActionItem
继承,这两个都与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屋!