Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set vertical size for the pop-up menu of a GtkComboBox

Tags:

python

gtk

gtk3

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()
like image 220
Matheus Saraiva Avatar asked Oct 21 '25 11:10

Matheus Saraiva


1 Answers

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:

enter image description here

like image 155
Jacob Vlijm Avatar answered Oct 23 '25 00:10

Jacob Vlijm