在 Kivy 中定位选项卡式面板 Header
Position Tabbed Panel Header in Kivy
我正在尝试创建自定义 TabbedPanel 来控制其外观和其他内容。但我似乎无法定位面板。在我的示例中,我已将条带着色为绿色以说明此问题。我确实看过这个 但我似乎无法弄明白。尝试将所有填充设置为零但没有成功。
面板略微偏移并且比条带略小(如绿色所示)。我该如何更改它和 remove/control 填充。
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
<Screen>:
canvas.before:
Color:
rgba: (0.8, 0.5, 1, 1)
Rectangle:
size: self.size
pos: self.pos
background_normal: ''
orientation: 'vertical'
padding: 50
CustomPanel:
CustomPanelItem:
Label:
text: 'Hello there'
<CustomPanel@TabbedPanel+CustomStrip>:
do_default_tab: False
tab_width: self.width
padding: 0, 0, 0, 0
<CustomPanelHeader@TabbedPanelHeader>:
text: 'Long Text for a Tab'
padding: 0, 0
<CustomPanelItem@TabbedPanelItem+CustomPanelHeader>:
text: 'Hello World Hello World Hello World'
padding: 0, 0
<CustomStrip@TabbedPanelStrip>:
canvas:
Color:
rgba: (0, 1, 0, 1) # green
Rectangle:
size: self.size
pos: self.pos
''')
class Screen(BoxLayout):
pass
class TestApp(App):
def build(self):
return Screen()
if __name__ == '__main__':
TestApp().run()
问题 1 - 向左 1 像素
but there still seems to be 1 px to the left ...?
根本原因 - 向左 1 像素
这是因为选项卡使用的 images 实际上是一个按钮。
解决方案 - 向左 1 像素
覆盖 class 规则,<TabbedPanelHeader>
为 background_normal: ''
和 background_color:
任何 rgba 颜色
问题 2 - 下方的腿部空间
... how do I deal with that leg room beneath?
说明
我认为条带/分隔符可能是设计使然。
问题
The panel is slightly offset and is slightly smaller than the strip
(as illustrated by the green color). How do I change this and
remove/control the padding.
解决方案
覆盖 class 规则中的 padding
,<StripLayout>
并删除对 padding
.
的所有引用
片段
...
<CustomPanelItem@TabbedPanelItem+CustomPanelHeader>:
text: 'Hello World Hello World Hello World'
<StripLayout>
padding: 0, 0, 0, 0
<TabbedPanelHeader>:
background_normal: ''
background_color: 0, 0, 1, 1 # blue
<CustomStrip@TabbedPanelStrip>:
canvas:
...
输出
我正在尝试创建自定义 TabbedPanel 来控制其外观和其他内容。但我似乎无法定位面板。在我的示例中,我已将条带着色为绿色以说明此问题。我确实看过这个
面板略微偏移并且比条带略小(如绿色所示)。我该如何更改它和 remove/control 填充。
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
<Screen>:
canvas.before:
Color:
rgba: (0.8, 0.5, 1, 1)
Rectangle:
size: self.size
pos: self.pos
background_normal: ''
orientation: 'vertical'
padding: 50
CustomPanel:
CustomPanelItem:
Label:
text: 'Hello there'
<CustomPanel@TabbedPanel+CustomStrip>:
do_default_tab: False
tab_width: self.width
padding: 0, 0, 0, 0
<CustomPanelHeader@TabbedPanelHeader>:
text: 'Long Text for a Tab'
padding: 0, 0
<CustomPanelItem@TabbedPanelItem+CustomPanelHeader>:
text: 'Hello World Hello World Hello World'
padding: 0, 0
<CustomStrip@TabbedPanelStrip>:
canvas:
Color:
rgba: (0, 1, 0, 1) # green
Rectangle:
size: self.size
pos: self.pos
''')
class Screen(BoxLayout):
pass
class TestApp(App):
def build(self):
return Screen()
if __name__ == '__main__':
TestApp().run()
问题 1 - 向左 1 像素
but there still seems to be 1 px to the left ...?
根本原因 - 向左 1 像素
这是因为选项卡使用的 images 实际上是一个按钮。
解决方案 - 向左 1 像素
覆盖 class 规则,<TabbedPanelHeader>
为 background_normal: ''
和 background_color:
任何 rgba 颜色
问题 2 - 下方的腿部空间
... how do I deal with that leg room beneath?
说明
我认为条带/分隔符可能是设计使然。
问题
The panel is slightly offset and is slightly smaller than the strip (as illustrated by the green color). How do I change this and remove/control the padding.
解决方案
覆盖 class 规则中的 padding
,<StripLayout>
并删除对 padding
.
片段
...
<CustomPanelItem@TabbedPanelItem+CustomPanelHeader>:
text: 'Hello World Hello World Hello World'
<StripLayout>
padding: 0, 0, 0, 0
<TabbedPanelHeader>:
background_normal: ''
background_color: 0, 0, 1, 1 # blue
<CustomStrip@TabbedPanelStrip>:
canvas:
...