Slider don't respond when extending FloatLayout

10 views
Skip to first unread message

Petr Marek

unread,
Jun 9, 2020, 5:09:56 AM6/9/20
to Kivy users support
Hello!
I have noticed, that when I write custom layout (extend FloatLayout class), that when I override function on_touch_down in this class, then slider added on this layout not respond. I have touchscreen, and when I drag slider, it is "frozen".

Here is my code:
import kivy 
from kivy.app import App 
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.slider import Slider

class MainApp(App): 
    def build(self):
        layout = MyLayout(size_hint=(0.4,0.2))

        slider = Slider( min=10, max=100) # create and add slider to MyLayout
        layout.add_widget(slider)
        return layout
        
class MyLayout(FloatLayout):
    def __init__(self, **kwargs):
        super(MyLayout, self).__init__(**kwargs)
        
    def on_touch_down(self, touch):
        if self.collide_point(*touch.pos):
            print("hit")
        else:
            print("miss")
            
app = MainApp()
app.run()

When I remove function on_touch_down(), everything works perfectly!
WHY? I need recognize touch event on this layout...So removing function is not solution for me.

Thanks!

Elliot Garbus

unread,
Jun 9, 2020, 8:27:56 AM6/9/20
to kivy-...@googlegroups.com

When you overload the on_touch_down() you are ‘consuming’ the touch.  You need to pass the touch along, so it can bubble to the other widgets.  See: https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=widget#widget-touch-event-bubbling

 

import kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.slider import Slider


class MainApp(App):
   
def build(self):
        layout = MyLayout(
size_hint=(0.4, 0.2
))
        slider = Slider(
min=10, max=100# create and add slider to MyLayout
       
layout.add_widget(slider)
       
return layout


class MyLayout(FloatLayout):
   
def __init__(self, **kwargs):
       
super(MyLayout, self).__init__(**kwargs)

   
def on_touch_down(self, touch):
       
if self.collide_point(*touch.pos):
           
print("hit")
       
else:
           
print("miss"
)
       
return super().on_touch_down(touch)

app = MainApp()
app.run()

--
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/90f723cc-86e4-4e69-b1ef-35de6bc62f1eo%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages