How to create custom libadwaita widget?

I’m trying to create custom button class which inherits from AdwSplitButton:

class SplitButton(Adw.SplitButton):
	def __init__(self):
		self.props.label = 'Open'
		self.props.tooltip_text = 'Open file'

And i’m getting this error:

/usr/lib/python3.10/site-packages/gi/ Warning: cannot derive '__main__+SplitButton' from final parent type 'AdwSplitButton'
  _gi.type_register(cls, namespace.get('__gtype_name__'))
Traceback (most recent call last):
  File "/home/vlad/Documents/Neutrino/", line 86, in <module>
    class SplitButton(Adw.SplitButton):
  File "/usr/lib/python3.10/site-packages/gi/", line 226, in __init__
    super(GObjectMeta, cls).__init__(name, bases, dict_)
  File "/usr/lib/python3.10/site-packages/gi/", line 205, in __init__
  File "/usr/lib/python3.10/site-packages/gi/", line 217, in _type_register
    _gi.type_register(cls, namespace.get('__gtype_name__'))
RuntimeError: could not create new GType: __main__+SplitButton (subclass of AdwSplitButton)

I get this with AdwHeaderBar too, but not with GtkHeaderBar or GtkButton.
What am I doing wrong?

Both AdwSplitButton and AdwHeaderBar are final classes: classes that cannot be derived any further.

You cannot create derived classes in Python for any type that is marked as “final”.

1 Like

Thank you! I guess I need to find another way to create custom widgets.

You can subclass Gtk.Widget and pack a SplitButton into it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.