Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click in Entry #23

Open
chang-zhao opened this issue Sep 6, 2023 · 1 comment
Open

Click in Entry #23

chang-zhao opened this issue Sep 6, 2023 · 1 comment

Comments

@chang-zhao
Copy link

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.

@chang-zhao
Copy link
Author

PS. Nevermind, it works with Gtk.EventControllerFocus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant