Access `visibility` property of PasswordEntry

Background

I have a window with two Gtk.PasswordEntry widgets, one to enter the password and the other to confirm it, like so:

I would like to synchronize them so that when a user clicks the peek icon on one, it triggers the text visibility of the other.

However, Gtk.PasswordEntry doesn’t expose the visibility property of the underlying text entry (I think it’s using Gtk.Text in the implementation?) widget, so doing it either through UI file, or in code doesn’t work.

I tried both:

PasswordEntry password_entry { }

PasswordEntry confirm_password_entry {
  visibility: bind password_entry.visibility bidirectional;
}

and:

g_object_bind_property(password_entry, "visibility", confirm_password_entry, "visibility", G_BINDING_BIDIRECTIONAL);

and it fails, unsurprisingly, with The source object of type GtkPasswordEntry has no property called 'visibility'.

Question: Is there a way to access either the property, or the underlying text entry widget? Or do I need to create my own widget and copy the implementation of PasswordEntry, and add the necessary code?

You should be able to do the latter with gtk_editable_get_delegate().

1 Like

That does precisely work for my use case. Thank you.