KivyMD
KivyMD copied to clipboard
MDDataTable has layout issues
Description of the Bug
When using nested Layouts the data table component has a weird looking layout and is displayed over other components.
Code and Logs
main.py:
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.navigationrail import (
MDNavigationRail,
MDNavigationRailItem,
)
from kivymd.uix.screen import MDScreen
from kivymd.uix.screenmanager import MDScreenManager
from screens.clients import ClientScreen
from screens.relations import RelationsScreen
from screens.mail import MailScreen
from screens.settings import SettingsScreen
from kivy.core.window import Window
Window.size = (1000, 750)
class PccApp(MDApp):
client_screen = ClientScreen()
relations_screen = RelationsScreen()
mail_screen = MailScreen()
settings_screen = SettingsScreen()
def build(self):
self.theme_cls.material_style = "M3"
self.theme_cls.primary_palette = "Orange"
return MDScreen(
MDBoxLayout(
MDNavigationRail(
MDNavigationRailItem(
text="Clients",
icon="account-multiple",
),
MDNavigationRailItem(
text="Relations",
icon="account-multiple",
),
MDNavigationRailItem(
text="Mail",
icon="email-outline",
),
MDNavigationRailItem(
text="Settings",
icon="cog-outline",
),
id="navigation_rail",
md_bg_color="#fffcf4",
selected_color_background="#e7e4c0",
ripple_color_item="#e7e4c0",
),
MDScreenManager(
self.client_screen.build(),
self.relations_screen.build(),
self.mail_screen.build(),
self.settings_screen.build(),
id="screen_manager_content",
),
id="root_box",
),
)
def switch_screen(self, *args, screen_manager_content=None):
"""
Called when tapping on rail menu items. Switches application screens.
"""
instance_navigation_rail, instance_navigation_rail_item = args
screen_manager_content.current = instance_navigation_rail_item.text.lower()
def on_start(self):
root_box = self.root.ids.root_box
navigation_rail = root_box.ids.navigation_rail
screen_manager_content = root_box.ids.screen_manager_content
navigation_rail.bind(
on_item_release=lambda *args: self.switch_screen(
*args, screen_manager_content=screen_manager_content
)
)
if __name__=="__main__":
PccApp().run()
clients.py:
from kivymd.uix.screen import MDScreen
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.anchorlayout import MDAnchorLayout
from kivymd.uix.label import MDLabel
from kivymd.uix.datatables import MDDataTable
from kivy.metrics import dp
class ClientScreen:
def build(self):
return MDScreen(
MDBoxLayout(
MDLabel(
text="Clients",
font_style="H3"
),
MDAnchorLayout(
MDDataTable(
use_pagination=True,
column_data=[
("Id", dp(30)),
("Name", dp(30)),
("Address", dp(30)),
("Birthday", dp(30))
],
row_data=[
(
"adjawdja8798",
"Max Mustermann",
"Addreseedkwa am buchenhain 14",
"17.05.1999"
)
]
),
padding=[0, 12]
),
padding=[12, 0],
pos_hint={"top": 1},
adaptive_height=True,
orientation="vertical"
),
name="clients",
)
Screenshots
Versions
- OS: Linux - PopOS 22.04
- Python: 3.10.12
- Kivy: 2.2.1
- KivyMD: 1.1.1