Disable mouse on DataTable? #5200
-
I have subclassed the DataTable and defined two "modes"
The fact that user is able to click with mouse also on the "moving the selected item" mode makes the app not work intuitively. I don't think mouse support is crucial for me, especially with the DataTable component. It would be easier to disable mouse actions than try to add support for it. I would like to either disable the ability to click cells (and change selected cell) on DataTable selectively or completely. I tried to override DataTable methods (without really checking what they do): async def _on_click(self, event) -> None: ...
def action_select_cursor(self) -> None: ...
def _on_mouse_move(self, event): ... but that did not have any effect. I also tried: async def on_event(self, event: events.Event) -> None:
if isinstance(event, MouseEvent):
event.prevent_default()
await super().on_event(event) mentioned here but that does not work. Any ideas how mouse clicks could be disabled? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can use the async def _on_click(self, event: events.Click) -> None:
event.prevent_default() |
Beta Was this translation helpful? Give feedback.
You can use the
prevent_default
method as mentioned here: https://textual.textualize.io/guide/events/#preventing-default-behaviors