Trying code like this I get the Scrollview to work nicely but the scroll_to() function doesn't do anything. The view still starts at the top position.
pixperhour = 60
tagHL = []
dayview = ScrollView(size_hint=(1,1))
test = BoxLayout(size_hint=(1,None), height=24*pixperhour, orientation='vertical')
dayview.add_widget(test)
for i in range(24):
tagHL.append(Label())
test.add_widget(tagHL[i])
tagHL[i].text = "Label "+str(i)
tagHL[i].color = (1, 1, 1)
tagHL[i].font_size = 30
dayview.scroll_to(tagHL[12])
I would expect the viewport of the scrollview to change so that the label tagHL[12] becomes visible. Am I doing it wrong or is the function bugged?
In order to make it happen as soon as the widget creation is done you can schedule it after (or, before) some (or, no) time as,
Clock.schedule_once(lambda *args : dayview.scroll_to(tagHL[12]),dt)wheredtcan be -1, 0 or any positive value.As a side note, if you are using
tagHLjust as a widget container then it will better to use thechildrenattribute of theBoxLayout,test. So, that will be like,