cryptotheo
cryptotheo

Reputation: 301

Kivymd MDSegmentedControl size

I'm trying to use the MDSegmentedControl but can't figure out how to adjust the overall width. It just runs off the screen when placed next to another widget.

KV = '''
MDScreen:
    
    
    
    MDCard:
        MDLabel:
            size_hint: None,1
            width: 200
            text: 'Gender'
        
        MDSegmentedControl:
            adaptive_width: True
            pos_hint: {"center_x": .5, "center_y": .5}
    
            MDSegmentedControlItem:
                text: "Male"
    
            MDSegmentedControlItem:
                text: "Female"
                
 
'''


class Example(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Orange"
        return Builder.load_string(KV)


Example().run()

Upvotes: 1

Views: 428

Answers (2)

rpi_guru
rpi_guru

Reputation: 309

For me, I had to give a fixed width of the segment panel children: https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/segmentedcontrol/segmentedcontrol.kv#L34

Its width is set as 320dp, no matter what size you give to the MDSegmentedControl widget.

So once the widget is created, adjust the width of the segment_panel children by yourself:

sc = MDSegmentedControl(size_hint_x=None, width=dp(200))
sc.ids.segment_panel.width = dp(200)

Upvotes: 1

smurfman
smurfman

Reputation: 1

This will do the job:

sc = MDSegmentedControl(pos_hint={'center_x': 0.5, 'center_y': 0.5}, size_hint=(1,None))
sc.ids.segment_panel.pos_hint = (1,1)

Upvotes: 0

Related Questions