Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:17:07+00:00 2026-06-17T06:17:07+00:00

I’m trying to make a custom widget that resembles the quick search entry that

  • 0

I’m trying to make a custom widget that resembles the “quick search” entry that Gtk uses on all TreeView-like widgets.

Here’s a simplified example of my initial idea:

from gi.repository import Gtk

class QuickSearch(Gtk.Bin):
    def __init__(self, *args, **kwargs):
        super(QuickSearch, self).__init__(*args, **kwargs)
        self.add(Gtk.Entry())

win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
search = QuickSearch()
win.add(search)
win.show_all()
Gtk.main()

The problems are the following:

  • If I use it alone, as in this example, there seems to be space allocated to the custom widget, but the GtkEntry is not shown on the screen. I tried various combinations of properties on the GtkEntry and the custom widget (hexpand, vexpand, margins, aligns, etc) with no avail.
  • If combined with other widgets, when I interactively query for the widget allocated height, it aparently is 1. On the screen, the widget effectively doesn’t appear (since it’s somewhat “squashed” between the other widgets).

So, there’s something I’m missing on the object initialization or how I’m using this custom widget? Is this a problem specific to GtkBin? I tried doing the same with a GtkBox and works flawlesly, but I think GtkBin is better suited for this particular widget.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:17:08+00:00Added an answer on June 17, 2026 at 6:17 am

    For some reason, Gtk.Bin is not allocating space to its child. If you implement the do_size_allocate virtual method then it works. Why the default implementation is not being called, I have no idea.

    from gi.repository import Gtk, Gdk
    
    class QuickSearch(Gtk.Bin):
        def __init__(self, *args, **kwargs):
            super(QuickSearch, self).__init__(*args, **kwargs)
            self.add(Gtk.Entry())
    
        def do_size_allocate(self, allocation):
            self.set_allocation(allocation)
            child_allocation = Gdk.Rectangle()
            border_width = self.get_border_width()
            child_allocation.x = allocation.x + border_width
            child_allocation.y = allocation.y + border_width
            child_allocation.width = allocation.width - 2 * border_width
            child_allocation.height = allocation.height - 2 * border_width
            self.get_child().size_allocate(child_allocation)
    
    win = Gtk.Window()
    win.connect("delete-event", Gtk.main_quit)
    search = QuickSearch()
    win.add(search)
    win.show_all()
    Gtk.main()
    

    However, I think inheriting from a Gtk.Frame is more appropriate for your purpose; it is a one-child container with a styleable border around it, which is what you want and more. And its size allocate method works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.