Skip to content

Add buttons or context menus to individual tree items #3967

Closed Answered by falkoschindler
moi90 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @moi90,

Currently the easiest way is to emit an event which is handled by the ui.tree element:

tree = ui.tree([
    {'id': 'numbers', 'description': 'Just some numbers', 'children': [
        {'id': '1', 'description': 'The first number'},
        {'id': '2', 'description': 'The second number'},
    ]},
], label_key='id')
tree.add_slot('default-body', '''
    <q-btn :props="props" @click="props.tree.$emit('item-click', props.node.description)">Click me</q-btn>
''')
tree.on('item-click', lambda e: ui.notify(e.args))

You can pass any information from props or props.node, respectively. In the QTree documentation you can find more information about the props object (QTree API > Slots > def…

Replies: 1 comment 1 reply

Comment options

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

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