Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Click in Entry #23

@chang-zhao

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.

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