Skip to content

Tree widget: First selected node stays highlighted after switching selection #5796

@SeyRyuu

Description

@SeyRyuu

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

When running the tree widget example from the Fyne documentation, selecting a tree node (e.g., a) and then selecting a different one (e.g., c) causes the new selection to appear correctly with the blue highlight. However, the first selected node (a) remains highlighted in a light grey color, as if it is still hovered.

How to reproduce

  1. Run the Fyne tree example code, also attached below
  2. Click on node a - it gets selected with a blue highlight
  3. Click on node c - it becomes blue as expected, but node a remains light grey (on hover color)

Screenshots

Image

Example code

package main

import (
    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/widget"
)

func main() {
    myApp := app.New()
    myWindow := myApp.NewWindow("Table Widget")

    tree := widget.NewTree(
        func(id widget.TreeNodeID) []widget.TreeNodeID {
            switch id {
            case "":
                return []widget.TreeNodeID{"a", "b", "c"}
            case "a":
                return []widget.TreeNodeID{"a1", "a2"}
            }
            return []string{}
        },
        func(id widget.TreeNodeID) bool {
            return id == "" || id == "a"
        },
        func(branch bool) fyne.CanvasObject {
            if branch {
                return widget.NewLabel("Branch template")
            }
            return widget.NewLabel("Leaf template")
        },
        func(id widget.TreeNodeID, branch bool, o fyne.CanvasObject) {
            text := id
            if branch {
                text += " (branch)"
            }
            o.(*widget.Label).SetText(text)
        })

    myWindow.SetContent(tree)
    myWindow.ShowAndRun()
}

Fyne version

v2.6.1

Go compiler version

1.24.2

Operating system and version

Linux pop_os 24.04 amd64 Wayland, Windows 11 amd64

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions