-
-
Notifications
You must be signed in to change notification settings - Fork 695
Open
Description
Description of the Bug
Hello,
i think there is a problem with MDDropdownMenu width.
if the width is set, it is no longer centered below a text field.
Default:
always works.
if menu.width = tf.width:
not centered
if menu.width > tf.width:
not centered
if menu.width < tf.width:
it seems to work as long as the Window is not resized, if the windows is resized to a certain size, it is again not centered.
Code and Logs
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.menu import MDDropdownMenu
KV = '''
MDScreen:
md_bg_color: self.theme_cls.backgroundColor
MDBoxLayout:
id: screen
orientation: "vertical"
padding: "50dp"
spacing: "10dp"
MDTextField:
id: tf1
pos_hint: {'center_x': .5, 'center_y': .6}
size_hint_x: None
width: "400dp"
on_focus: if self.focus: app.menu.open()
MDTextFieldHintText:
text: "MDDropdownMenu #1 Default"
MDTextField:
id: tf2
mode: "filled"
pos_hint: {'center_x': .5, 'center_y': .6}
size_hint_x: None
width: "400dp"
on_focus: if self.focus: app.menu2.open()
MDTextFieldHintText:
text: "MDDropdownMenu #2 menu.width = tf.widt"
MDTextField:
id: tf3
pos_hint: {'center_x': .5, 'center_y': .6}
size_hint_x: None
width: "400dp"
on_focus: if self.focus: app.menu3.open()
MDTextFieldHintText:
text: "MDDropdownMenu #3 menu.width > tf.widt"
MDTextField:
id: tf4
pos_hint: {'center_x': .5, 'center_y': .6}
size_hint_x: None
width: "400dp"
on_focus: if self.focus: app.menu4.open()
MDTextFieldHintText:
text: "MDDropdownMenu #3 menu.width < tf.widt"
Widget:
'''
#1 Changing Window Size cuts dropdown width in half?
class Example(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.screen = Builder.load_string(KV)
menu_items = [
{
"text": f"Item {i}",
"on_release": lambda x=f"Item {i}": self.set_item(x),
} for i in range(5)
]
self.menu = MDDropdownMenu(
caller=self.screen.ids.tf1,
items=menu_items,
position="bottom"
)
self.menu2 = MDDropdownMenu(
caller=self.screen.ids.tf2,
items=menu_items,
position="bottom",
width=400
)
self.menu3 = MDDropdownMenu(
caller=self.screen.ids.tf3,
items=menu_items,
position="bottom",
width=600
)
self.menu4 = MDDropdownMenu(
caller=self.screen.ids.tf4,
items=menu_items,
position="bottom",
width=300
)
def set_item(self, text_item):
self.screen.ids.field.text = text_item
self.menu.dismiss()
def build(self):
return self.screen
Example().run()Screenshots
Versions
- OS: Win11
- Python: 3.12.4
- Kivy: 2.3.1
- KivyMD: 2.0.1.dev0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels