Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
Show password button on entry in gtk

Is there a way in gtk to make an eye icon on the right of an entry to show a password? I know there is a way to make a checkbox under an entry to show the password, but I want the button to be inside the entry, not outside. To put it simply:

What i'm looking for is this: show password icon

...and not this: show password checkbox

(I'm sorry that I cant embed the image. The site says I need 10 reputation first. I actually used to have almost 300 untill I got banned from a dislike attack. Please think before you dislike because it literally only takes ~20 to permenantly ban a year-long user. If anyone has enough reputation to edit the question and add the images in, please do)

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can put an icon to Gtk.Entry with the set_icon_from_ functions, for example set_icon_from_name.

So you need to set the icon to for example to the view-reveal-symbolic.symbolic icon, make it clickable with set_icon_activatable and then in the signal handler for the icon-press event you need to set_visibility to either hide or show the text (and also change the icon to something like view-conceal-symbolic.symbolic).

So the Gtk.Entry code could look like this

GtkWidget *entry = gtk_entry_new();
gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(entry), 
                                  GTK_ENTRY_ICON_SECONDARY, 
                                  "view-reveal-symbolic.symbolic");
gtk_entry_set_icon_activatable(GTK_ENTRY(entry), GTK_ENTRY_ICON_SECONDARY, TRUE);
g_signal_connect(entry, "icon-press", G_CALLBACK (on_icon_press), NULL);

and the signal handler

void on_icon_press(GtkWidget *widget, gpointer data) {   
    gboolean visible = gtk_entry_get_visibility(GTK_ENTRY(widget));
    
    if (visible) {
        gtk_entry_set_visibility(GTK_ENTRY(widget), FALSE);
        gtk_entry_set_icon_from_icon_name(GTK_ENTRY(widget), 
                                          GTK_ENTRY_ICON_SECONDARY, 
                                          "view-reveal-symbolic.symbolic");
    } else {
        gtk_entry_set_visibility(GTK_ENTRY(widget), TRUE);
        gtk_entry_set_icon_from_icon_name(GTK_ENTRY(widget), 
                                          GTK_ENTRY_ICON_SECONDARY, 
                                          "view-conceal-symbolic.symbolic");
    }
}

And you'll get something like this:

enter image description here enter image description here

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda