Dynamic Content Sizing with Minimum Width in Kivy ScrollView

63 views
Skip to first unread message

William Volpe

unread,
Apr 1, 2024, 7:50:44 PMApr 1
to Kivy users support
I'm trying to achieve a specific behavior with a ScrollView in Kivy where its content dynamically resizes with the ScrollView itself, using size_hint_x: 1. However, I need the content to stop resizing and enable scrolling when it reaches a minimum width.

I’ve tried various settings with size_hint and minimum size properties but haven’t nailed it yet.

I'm able to achieve the dynamic resizing and minimum width by using size_hint_x:1 and width: self.minimum_width, however the scrolling doesn't enable. I've checked that do_scroll_x = True, and I've seen in the docs that you must deactivate the size_hint in the direction you are trying to scroll, but then the content won't grow with the scroll view as it's resized. 

elli...@cox.net

unread,
Apr 1, 2024, 7:56:44 PMApr 1
to kivy-...@googlegroups.com
For the Boxlayout under the ScrollView use:
size_hint_x:  None
width: self.minimum_width 

If that doesn't work, share a minimal, executable example.

From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of William Volpe <willc...@gmail.com>
Sent: Monday, April 1, 2024 4:50 PM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] Dynamic Content Sizing with Minimum Width in Kivy ScrollView
 
I'm trying to achieve a specific behavior with a ScrollView in Kivy where its content dynamically resizes with the ScrollView itself, using size_hint_x: 1. However, I need the content to stop resizing and enable scrolling when it reaches a minimum width.

I’ve tried various settings with size_hint and minimum size properties but haven’t nailed it yet.

I'm able to achieve the dynamic resizing and minimum width by using size_hint_x:1 and width: self.minimum_width, however the scrolling doesn't enable. I've checked that do_scroll_x = True, and I've seen in the docs that you must deactivate the size_hint in the direction you are trying to scroll, but then the content won't grow with the scroll view as it's resized. 

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/1468eac6-827f-44c0-b898-b2d3802727dfn%40googlegroups.com.

ElliotG

unread,
Apr 1, 2024, 8:17:09 PMApr 1
to Kivy users support
Re-reading your post - I don't think  understand what you are trying to do. 
Do you want a button in a BoxLayout under a ScrollView, and you want the button to size with the ScrollView?
If so size the BoxLayout to be size_hint_x: None, and width: self.minimum_widget.  Look at using size_hint_min on the button.  See: https://kivy.org/doc/stable/api-kivy.uix.widget.html#kivy.uix.widget.Widget.size_hint_min

ElliotG

unread,
Apr 1, 2024, 8:45:49 PMApr 1
to Kivy users support
I did some quick experiments.  Let me know if this is what you are looking for...

At the top of the widget are 2 buttons in a scrollview, size_hint_min and size_hint_max are used to control the size of the button "min max".  I don't think this is what you are looking for.

Under the ScrollView is a BoxLayout,   the width of the first button is controlled dynamically, based on the width of the scrollview.  Is this what you wanted?

from kivy.app import App
from kivy.lang import Builder

kv = """
BoxLayout:
    orientation: 'vertical'
    BoxLayout:   # this box layout shows how size_hint min and max can limit a widget size...
        size_hint_y: None
        height: dp(48)
        Button:
            text: 'min max'
            size_hint_max_x: 400
            size_hint_min_x: 100
        Button:
            text: 'size_hint 1'
    Label:
        text: 'Scroll Dynamic Button'
    ScrollView:
        id: sv
        do_scroll_y: False
        BoxLayout:
            id: scroll_box
            size_hint: None, None
            size: self.minimum_width, dp(48)
            Button:
                text: 'Dynamic Button'
                size_hint_x: None
                width: dp(200) if sv.width <= dp(400) else sv.width - dp(200)  # dynamically control the width
            Button:
                size_hint_x: None
                width: dp(600)
                text: 'Fixed Long Button'  
"""


class ScrollXDynamicApp(App):
    def build(self):
        return Builder.load_string(kv)


ScrollXDynamicApp().run()



Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages