0

I would like to embed another widget in one end of a GTK+ 3 text entry box, a bit like many browsers do with search or protocol security "chips": Left hand side of Chromium search bar

I know I can set an icon on a text entry with

entry = Gtk.Entry()
entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, icon_name)

Even if I pass my own GdkPixbuf to set_icon_from_pixbuf this still limits me to icon sizes, when I want some arbitrary size (at least horizontally) depending on the "chip" content.

I also tried to "shunt" the text over with set_margin_left, but this moved the left edge of the whole entry box over, rather than the text within the box.

What would be an effective way to embed some other GTK+ widget (hopefully of any complexity, so I can make the chip more interactive) within a text entry?

2
  • 1
    You should have a look at how it is done in GdTaggedEntry from libgd. This is used in the new search in nautilus 3.20. You can also try to use it but you would have to compile it first. For that, the source code of gnome-music might be interesting because it uses libgd as well and is written in python. Commented Apr 26, 2016 at 15:47
  • Are you still looking for help with this or have you figured it out? Commented May 8, 2016 at 2:23

2 Answers 2

2

GtkEntry is not a container, so it cannot have child widgets.

The appropriate way to implement what you see in the screenshot is to use a separate container and style it appropriately.

Sign up to request clarification or add additional context in comments.

Comments

1

Have you considered putting the entry inside a frame, and restyling stuff to make it look like it was inside an entry? Then you could use standard containers to put whatever widgets next to the text entry spaces that you wanted.

The downside is that clicking your "icon" doesn't focus the entry automatically, but it makes that action totally configurable.

2 Comments

I had considered it, and haven't discounted it yet, but "faking up" a widget that looks and feels like a text entry, when it actually just needs a bit of extra space on the left of the text seemed like overkill.
Not really; just add the entry class using gtk_style_context_add_class(). (This is what ebassi is suggesting.) I might write a quick sample program to demonstrate later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.