kivymd / KivyMD

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
https://kivymd.readthedocs.io
MIT License
2.21k stars 665 forks source link

MDListItem. The height of the element in the KV file is not set #1638

Open HeaTTheatR opened 6 months ago

HeaTTheatR commented 6 months ago

Are there anything special with MDListItem that prevent me from subclassing it? I try to create a custom MDListItem to configure the height, md_bg_color and other property, it's working when defined on the MDListItem, but not when creating a subclass.

from kivy.lang import Builder

from kivymd.app import MDApp
from kivy.utils import get_color_from_hex
from kivymd.uix.list import MDListItem

KV = '''
<MyListItem>:
    height: "100dp"
    padding: "0dp"
    spacing: "0dp"

MDScreen:
    md_bg_color: app.theme_cls.surfaceColor

    MDBoxLayout:
        orientation: 'vertical'

        MDList:

            MyListItem:

                MDListItemHeadlineText:
                    text: "My Custom Item 1"

                MDListItemTrailingIcon:
                    icon: "play"

            MyListItem:

                MDListItemHeadlineText:
                    text: "My Custom Item 2"

                MDListItemTrailingIcon:
                    icon: "chevron-right"

            MyListItem:

                MDListItemHeadlineText:
                    text: "My Custom Item 3"

                MDListItemTrailingIcon:
                    icon: "chevron-right"

            MyListItem:
                height: "100dp"
                padding: "0dp"
                spacing: "0dp"

                MDListItemHeadlineText:
                    text: "My Custom Item 3"

                MDListItemTrailingIcon:
                    icon: "chevron-right"
'''

class MyListItem(MDListItem):
    pass

class Example(MDApp):
    def build(self):
        return Builder.load_string(KV)

Example().run()

The issue is here - https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/list/list.kv#L43

image