KivyMD icon indicating copy to clipboard operation
KivyMD copied to clipboard

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

Open HeaTTheatR opened this issue 4 months ago • 0 comments

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

HeaTTheatR avatar Mar 08 '24 15:03 HeaTTheatR