In GTK3 I am using allmost always the “child
”/"parent
" properties more over when I need to avoid UI files (pelase do not ask why), like in the case of GtkShortcutsWindow
:
#include <gtk/gtk.h>
static GtkShortcutsWindow *create_shortcuts_window ( void )
{
/// ***
GtkShortcutsWindow *shortcuts_window = g_object_new ( GTK_TYPE_SHORTCUTS_WINDOW,
"modal", TRUE,
"section-name", "My_Section",
"view-name", "view",
NULL );
/// ***
GtkShortcutsSection *shrt_section = g_object_new ( GTK_TYPE_SHORTCUTS_SECTION,
"max-height", 10,
"visible", TRUE,
"section-name", "My_Section",
"title", "What ever",
"parent", shortcuts_window,
NULL );
/// ***
GtkShortcutsGroup *shrt_group = g_object_new ( GTK_TYPE_SHORTCUTS_GROUP,
"visible", 1,
"title", "The Accelerator",
"view", "My_View",
"parent", shrt_section,
NULL );
/// ***
g_object_new ( GTK_TYPE_SHORTCUTS_SHORTCUT,
"visible", TRUE,
"shortcut-type", GTK_SHORTCUT_ACCELERATOR,
"accelerator", "<ctl><alt>G",
"title", "Take a Look",
"subtitle", "Did you?",
"subtitle-set", TRUE,
"direction", GTK_TEXT_DIR_LTR,
"parent", shrt_group,
NULL );
/// ***
return shortcuts_window;
}
static void activate_clbk ( GtkApplication *application )
{
g_return_if_fail ( GTK_IS_APPLICATION ( application ) );
GtkWidget *window;
GtkShortcutsWindow *shortcuts_window;
/// ***
window = gtk_application_window_new ( application );
/// ***
shortcuts_window = create_shortcuts_window ();
gtk_application_window_set_help_overlay ( GTK_APPLICATION_WINDOW ( window ), shortcuts_window );
/// ***
gtk_window_present ( GTK_WINDOW ( window ) );
gtk_window_present ( GTK_WINDOW ( shortcuts_window ) );
}
int main ( void )
{
GtkApplication *application;
/// ***
application = gtk_application_new ( "this.is.my.app", G_APPLICATION_FLAGS_NONE );
/// ***
g_signal_connect_swapped ( application, "activate", G_CALLBACK ( activate_clbk ), application );
/// ***
return g_application_run ( G_APPLICATION ( application ), 0, NULL );
}
The above code compiles fine in GTK4 as well but I get in terminal the following:
(GtkApplication:4936): GLib-GObject-CRITICAL **: 12:28:38.007: g_object_new_is_valid_property: property 'parent' of object class 'GtkShortcutsSection' is not writable
(GtkApplication:4936): GLib-GObject-CRITICAL **: 12:28:38.007: g_object_new_is_valid_property: property 'parent' of object class 'GtkShortcutsGroup' is not writable
(GtkApplication:4936): GLib-GObject-CRITICAL **: 12:28:38.008: g_object_new_is_valid_property: property 'parent' of object class 'GtkShortcutsShortcut' is not writable
How should I go in GTK4 with this one?
The way Object Hierarchy works:
GObject
╰── GInitiallyUnowned
╰── GtkWidget
╰── GtkBox
╰── GtkShortcutsSection
looks like the GtkShortcutsSection
is derived from GtkWidget
, but id does not inerhit the “parent” property or at least does not let me write it.
What I am missing here?