Skip to content

Enabling horizontal scroll in a ListView #5790

Answered by TomJGooding
dlalaj asked this question in Q&A
Discussion options

You must be logged in to vote

I think you just need to set the ListItem width to auto, as it is 1fr by default. Here's a minimal example:

EDIT: Actually, the problem with this is that unless your items are all the same width, the highlighting for the current item will be different widths...

from textual.app import App, ComposeResult
from textual.widgets import Label, ListItem, ListView


class ExampleApp(App):
    CSS = """
    Screen {
        align: center middle;
    }

    ListView {
        width: 80;
        height: 24;

        overflow-x: auto;

        & > ListItem {
            width: auto;
        }
        
    }
    """

    def compose(self) -> ComposeResult:
        yield ListView(
            *[ListItem(

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dlalaj
Comment options

Answer selected by dlalaj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants