Skip to content
This repository was archived by the owner on May 1, 2026. It is now read-only.
This repository was archived by the owner on May 1, 2026. It is now read-only.

Click in Entry #23

Description

@chang-zhao

Thank you for this tutorial. Until today I haven't found one for gtk4, so this is a blessing.

Currently I'm struggling with a simple question: how to detect a mouse button click in an Entry?

(I want to open a popup when left-click inside an Entry).

In GTK3, I did (in my entry class):

        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect("button-press-event", self.onClick)

but GTK4 doesn't have "button-press-event", right?

After some search, I managed to do something like this:

        self.leftClick = Gtk.GestureClick()
        self.leftClick.set_button(1)
        self.leftClick.connect("pressed", self.onClick)
        self.add_controller(self.leftClick)

but the callback works only when I click on the entry's border, but not in the text field.

It would be nice to know how it works.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions