I created a GtkComboBox with dozens of items. When I perform I see that the pop-up menu containing the items is very vertically large. How do I set a maximum size? I checked the documentation and I not found a method to define it.
Example:
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class ComboBox(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("ComboBox")
self.set_default_size(150, -1)
self.connect("destroy", Gtk.main_quit)
slist = Gtk.ListStore(str, str)
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
slist.append(['01', 'Ferro'])
slist.append(['07', 'Uranio'])
slist.append(['08', 'Cobalto'])
combobox = Gtk.ComboBox()
combobox.set_model(slist)
self.add(combobox)
cell1 = Gtk.CellRendererText()
cell2 = Gtk.CellRendererText()
combobox.pack_start(cell1, True)
combobox.pack_start(cell2, True)
combobox.add_attribute(cell1, "text", 0)
combobox.add_attribute(cell2, "text", 1)
window = ComboBox()
window.show_all()
Gtk.main()
As far as I know (and can find), it is impossible to set the number of rows in a GtkComboBox drop down menu.
If you insist on using Gtk.ComboBox()
, you can however reduce the height in case of large amounts of entries by using:
combobox.set_wrap_width(5)
Which would show:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With