I am just starting out with Gtk4 so this might be have an obvious reason, but a button in the PopoverMenu is only visible if you hover over it. This is not my intention and it would be awesome if someone could help me. This phenomenon happens when:
- You place a MenuButton inside a ListBox
- The user selects the ListBoxRow where the MenuButton is located
- Inside the PopoverMenu is a custom item which is a button
- The button has the property has-frame=False
Buttons without the has-frame property are always visible. I created some code that demonstrates this all:
import sys
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
menu_ui = '''
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<menu id="test_menu">
<section>
<attribute name="display-hint">horizontal-buttons</attribute>
<item>
<attribute name="custom">button1</attribute>
</item>
<item>
<attribute name="custom">button2</attribute>
</item>
</section>
</menu>
</interface>
'''
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
scrolled_window = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
self.set_child(scrolled_window)
list_box = Gtk.ListBox(hexpand=True, vexpand=True)
scrolled_window.set_child(list_box)
row1 = Gtk.ListBoxRow()
row1.set_child(Gtk.Label(label="If I am highlighted you can see 2 buttons!"))
list_box.append(row1)
row = Gtk.ListBoxRow()
box = Gtk.Box(orientation="horizontal", hexpand=True, vexpand=True)
box.append(Gtk.Label(label="If I am highlighted you can't see the first button!"))
row.set_child(box)
list_box.append(row)
menu_button = Gtk.MenuButton(hexpand=False)
box.append(menu_button)
builder = Gtk.Builder().new_from_string(menu_ui, -1)
menu =builder.get_object("test_menu")
menu_button.set_menu_model(menu)
menu_button.get_popover().add_child(Gtk.Button(icon_name="go-top-symbolic", has_frame=False), "button1")
menu_button.get_popover().add_child(Gtk.Button(icon_name="go-top-symbolic"), "button2")
class MyApp(Gtk.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
def on_activate(self, app):
self.win = MainWindow(application=app)
self.win.present()
app = MyApp(application_id="com.example.GtkApplication")
app.run(sys.argv)
Sorry for long post but help would be awesome