It derives from <GtkWidget>.
Switches between children using tabs.
There are many configuration options for
<GtkNotebook>. Among other things, you can
choose on which edge the tabs appear (see notebook:set-tab-pos), whether, if there are too many
tabs to fit the notebook should be made bigger or scrolling arrows added
(see notebook:set-scrollable), and
whether there will be a popup menu allowing the users to switch pages.
(see notebook:popup-enable).
The <GtkNotebook> implementation of the
<GtkBuildable> interface supports placing
children into tabs by specifying “tab” as the “type” attribute of a
<child> element. Note that the content of the tab must be
created before the tab can be filled. A tab child can be specified
without specifying a <child> type attribute.
To add a child widget in the notebooks action area, specify
"action-start" or “action-end” as the “type” attribute of the
<child> element.
An example of a UI definition fragment with
<GtkNotebook>:
<object class="GtkNotebook">
<child>
<object class="GtkLabel" id="notebook-content">
<property name="label">Content</property>
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="notebook-tab">
<property name="label">Tab</property>
</object>
</child>
</object>
<GtkNotebook> supports the following keyboard
shortcuts:
Additionally, the following signals have default keybindings:
notebook:change-current-page
notebook:focus-tab
notebook:move-focus-out
notebook:reorder-tab
notebook:select-page
Tabs support drag-and-drop between notebooks sharing the same
group-name, or to new windows by handling the
::create-window signal.
<GtkNotebook> defines a set of built-in actions:
menu.popup opens the tabs context menu.
notebook
├── header.top
│ ├── [<action widget>]
│ ├── tabs
│ │ ├── [arrow]
│ │ ├── tab
│ │ │ ╰── <tab label>
┊ ┊ ┊
│ │ ├── tab[.reorderable-page]
│ │ │ ╰── <tab label>
│ │ ╰── [arrow]
│ ╰── [<action widget>]
│
╰── stack
├── <child>
┊
╰── <child>
<GtkNotebook> has a main CSS node with name
notebook, a subnode with name header and below that a
subnode with name tabs which contains one subnode per tab with
name tab.
If action widgets are present, their CSS nodes are placed next to the
tabs node. If the notebook is scrollable, CSS nodes with name
arrow are placed as first and last child of the tabs node.
The main node gets the .frame style class when the notebook has a
border (see notebook:set-show-border).
The header node gets one of the style class .top, .bottom,
.left or .right, depending on where the tabs are placed.
For reorderable pages, the tab node gets the .reorderable-page
class.
A tab node gets the .dnd style class while it is moved
with drag-and-drop.
The nodes are always arranged from left-to-right, regardless of text direction.
<GtkNotebook> uses the following roles:
Gtk.AccessibleRole.group for the notebook widget
Gtk.AccessibleRole.tab_list for the list of tabs
Gtk.AccessibleRole.tab role for each tab
Gtk.AccessibleRole.tab_panel for each page
If #t, pressing the right mouse button on the notebook shows a
page switching menu.
Its value is a boolean.
Set it with (set! (notebook:enable-popup self) value).
Group name for tab drag and drop.
Its value is a string, or #f.
Set it with (set! (notebook:group-name self) value).
The index of the current page.
Its value is a 32-bit integer.
Set it with (set! (notebook:page self) value).
A selection model with the pages.
Its value is a <GListModel>, or #f.
It is read only.
If #t, scroll arrows are added if there are too many pages to
fit.
Its value is a boolean.
Set it with (set! (notebook:scrollable self) value).
Whether the border should be shown.
Its value is a boolean.
Set it with (set! (notebook:show-border self) value).
Whether tabs should be shown.
Its value is a boolean.
Set it with (set! (notebook:show-tabs self) value).
Which side of the notebook holds the tabs.
Its value is a <GtkPositionType> (or, to set
it, one of its symbols).
Set it with (set! (notebook:tab-pos self) value).
Appends a page to self.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the <GtkWidget> to use as the contents of the page
Passed, or left out: a <GtkWidget>, or #f.
the <GtkWidget> to be used as the label for the
page, or #f to use the default label, “page N”
Returned: a 32-bit integer.
the index (starting from 0) of the appended page in the notebook, or -1 if function fails
Appends a page to self, specifying the widget to use as the label in the popup menu.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the <GtkWidget> to use as the contents of the page
Passed, or left out: a <GtkWidget>, or #f.
the <GtkWidget> to be used as the label for the
page, or #f to use the default label, “page N”
Passed, or left out: a <GtkWidget>, or #f.
the widget to use as a label for the page-switch menu, if that is
enabled. If #f, and tab-label is a
<GtkLabel> or #f, then the menu label will be
a newly created label with the same text as tab-label; if
tab-label is not a <GtkLabel>,
menu-label must be specified if the page-switch menu is to be
used.
Returned: a 32-bit integer.
the index (starting from 0) of the appended page in the notebook, or -1 if function fails
Removes the child from the notebook.
This function is very similar to notebook:remove-page, but additionally informs the
notebook that the removal is happening as part of a tab DND operation,
which should not be cancelled.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
a child
Gets one of the action widgets.
See notebook:set-action-widget.
Passed: a <GtkNotebook>.
Passed: a <GtkPackType>, or one of its symbols.
pack type of the action widget to receive
Returned: a <GtkWidget>, or #f.
The action widget with the given pack-type or #f when this
action widget has not been set
Returns the page number of the current page.
Passed: a <GtkNotebook>.
Returned: a 32-bit integer.
the index (starting from 0) of the current page in the notebook. If the notebook has no pages, then -1 will be returned.
Gets the current group name for self.
Passed: a <GtkNotebook>.
Returned: a string, or #f.
the group name, or #f if none is set
Retrieves the menu label widget of the page containing child.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
a widget contained in a page of self
Returned: a <GtkWidget>, or #f.
the menu label, or #f if the notebook page does not have a menu
label other than the default (the tab label).
Retrieves the text of the menu label for the page containing child.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the child widget of a page of the notebook.
Returned: a string, or #f.
the text of the tab label, or #f if the widget does not have a
menu label other than the default menu label, or the menu label widget
is not a <GtkLabel>. The string is owned by the
widget and must not be freed.
Gets the number of pages in a notebook.
Passed: a <GtkNotebook>.
Returned: a 32-bit integer.
the number of pages in the notebook
Returns the child widget contained in page number page-num.
Passed: a <GtkNotebook>.
Passed: a 32-bit integer.
the index of a page in the notebook, or -1 to get the last page
Returned: a <GtkWidget>, or #f.
the child widget, or #f if page-num is out of bounds
Returns the <GtkNotebookPage> for
child.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
a child of self
Returned: a <GtkNotebookPage>.
the <GtkNotebookPage> for child
Returns a <GListModel> that contains the
pages of the notebook.
This can be used to keep an up-to-date view. The model also implements
<GtkSelectionModel> and can be used to
track and modify the visible page.
Passed: a <GtkNotebook>.
Returned: a <GListModel>.
a <GListModel> for the notebook’s children
Returns whether the tab label area has arrows for scrolling.
Passed: a <GtkNotebook>.
Returned: a boolean.
#t if arrows for scrolling are present
Returns whether a bevel will be drawn around the notebook pages.
Passed: a <GtkNotebook>.
Returned: a boolean.
#t if the bevel is drawn
Returns whether the tabs of the notebook are shown.
Passed: a <GtkNotebook>.
Returned: a boolean.
#t if the tabs are shown
Returns whether the tab contents can be detached from self.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
a child <GtkWidget>
Returned: a boolean.
#t if the tab is detachable.
Returns the tab label widget for the page child.
#f is returned if child is not in self or if no tab
label has specifically been set for child.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the page
Returned: a <GtkWidget>, or #f.
the tab label
Retrieves the text of the tab label for the page containing child.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
a widget contained in a page of self
Returned: a string, or #f.
the text of the tab label, or #f if the tab label widget is not a
<GtkLabel>. The string is owned by the widget and
must not be freed.
Gets the edge at which the tabs are drawn.
Passed: a <GtkNotebook>.
Returned: a <GtkPositionType>.
the edge at which the tabs are drawn
Gets whether the tab can be reordered via drag and drop or not.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
a child <GtkWidget>
Returned: a boolean.
#t if the tab is reorderable.
Insert a page into self at the given position.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the <GtkWidget> to use as the contents of the page
Passed: a <GtkWidget>, or #f.
the <GtkWidget> to be used as the label for the
page, or #f to use the default label, “page N”
Passed: a 32-bit integer.
the index (starting at 0) at which to insert the page, or -1 to append the page after all other pages
Returned: a 32-bit integer.
the index (starting from 0) of the inserted page in the notebook, or -1 if function fails
Insert a page into self at the given position, specifying the widget to use as the label in the popup menu.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the <GtkWidget> to use as the contents of the page
Passed: a <GtkWidget>, or #f.
the <GtkWidget> to be used as the label for the
page, or #f to use the default label, “page N”
Passed: a <GtkWidget>, or #f.
the widget to use as a label for the page-switch menu, if that is
enabled. If #f, and tab-label is a
<GtkLabel> or #f, then the menu label will be
a newly created label with the same text as tab-label; if
tab-label is not a <GtkLabel>,
menu-label must be specified if the page-switch menu is to be
used.
Passed: a 32-bit integer.
the index (starting at 0) at which to insert the page, or -1 to append the page after all other pages.
Returned: a 32-bit integer.
the index (starting from 0) of the inserted page in the notebook
Creates a new <GtkNotebook> widget with no pages.
Returned: a <GtkWidget>.
the newly created <GtkNotebook>
Switches to the next page.
Nothing happens if the current page is the last page.
Passed: a <GtkNotebook>.
Finds the index of the page which contains the given child widget.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
Returned: a 32-bit integer.
the index of the page containing child, or -1 if child is not in the notebook
Disables the popup menu.
Passed: a <GtkNotebook>.
Enables the popup menu.
If the user clicks with the right mouse button on the tab labels, a menu with all the pages will be popped up.
Passed: a <GtkNotebook>.
Prepends a page to self.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the <GtkWidget> to use as the contents of the page
Passed, or left out: a <GtkWidget>, or #f.
the <GtkWidget> to be used as the label for the
page, or #f to use the default label, “page N”
Returned: a 32-bit integer.
the index (starting from 0) of the prepended page in the notebook, or -1 if function fails
Prepends a page to self, specifying the widget to use as the label in the popup menu.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the <GtkWidget> to use as the contents of the page
Passed, or left out: a <GtkWidget>, or #f.
the <GtkWidget> to be used as the label for the
page, or #f to use the default label, “page N”
Passed, or left out: a <GtkWidget>, or #f.
the widget to use as a label for the page-switch menu, if that is
enabled. If #f, and tab-label is a
<GtkLabel> or #f, then the menu label will be
a newly created label with the same text as tab-label; if
tab-label is not a <GtkLabel>,
menu-label must be specified if the page-switch menu is to be
used.
Returned: a 32-bit integer.
the index (starting from 0) of the prepended page in the notebook, or -1 if function fails
Switches to the previous page.
Nothing happens if the current page is the first page.
Passed: a <GtkNotebook>.
Removes a page from the notebook given its index in the notebook.
Passed: a <GtkNotebook>.
Passed: a 32-bit integer.
the index of a notebook page, starting from 0. If -1, the last page will be removed.
Reorders the page containing child, so that it appears in position position.
If position is greater than or equal to the number of children in the list or negative, child will be moved to the end of the list.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the child to move
Passed: a 32-bit integer.
the new position, or -1 to move to the end
Sets widget as one of the action widgets.
Depending on the pack type the widget will be placed before or after the
tabs. You can use a <GtkBox> if you need to pack more
than one widget on the same side.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
Passed: a <GtkPackType>, or one of its symbols.
pack type of the action widget
Switches to the page number page-num.
Note that due to historical reasons, GtkNotebook refuses to switch to a page unless the child widget is visible. Therefore, it is recommended to show child widgets before adding them to a notebook.
Passed: a <GtkNotebook>.
Passed: a 32-bit integer.
index of the page to switch to, starting from 0. If negative, the last page will be used. If greater than the number of pages in the notebook, nothing will be done.
Sets a group name for self.
Notebooks with the same name will be able to exchange tabs via drag and
drop. A notebook with a #f group name will not be able to
exchange tabs with any other notebook.
Passed: a <GtkNotebook>.
Passed, or left out: a string, or #f.
the name of the notebook group, or #f to unset it
Changes the menu label for the page containing child.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the child widget
Passed, or left out: a <GtkWidget>, or #f.
the menu label, or #f for default
Creates a new label and sets it as the menu label of child.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the child widget
Passed: a string.
the label text
Sets whether the tab label area will have arrows for scrolling if there are too many tabs to fit in the area.
Passed: a <GtkNotebook>.
Passed: a boolean.
#t if scroll arrows should be added
Sets whether a bevel will be drawn around the notebook pages.
This only has a visual effect when the tabs are not shown.
Passed: a <GtkNotebook>.
Passed: a boolean.
#t if a bevel should be drawn around the notebook
Sets whether to show the tabs for the notebook or not.
Passed: a <GtkNotebook>.
Passed: a boolean.
#t if the tabs should be shown
Sets whether the tab can be detached from self to another notebook or widget.
Note that two notebooks must share a common group identifier (see
notebook:set-group-name) to allow
automatic tabs interchange between them.
If you want a widget to interact with a notebook through DnD (i.e.:
accept dragged tabs from it) it must be set as a drop destination by
adding to it a <GtkDropTarget> controller that
accepts the GType GTK_TYPE_NOTEBOOK_PAGE. The :value of
said drop target will be preloaded with a
<GtkNotebookPage> object that corresponds to
the dropped tab, so you can process the value via ::accept or
::drop signals.
Note that you should use notebook:detach-tab instead of notebook:remove-page if you want to remove the tab from
the source notebook as part of accepting a drop. Otherwise, the source
notebook will think that the dragged tab was removed from underneath the
ongoing drag operation, and will initiate a drag cancel animation.
static void
on_drag_data_received (GtkWidget *widget,
GdkDrop *drop,
GtkSelectionData *data,
guint time,
gpointer user_data)
{
GtkDrag *drag;
GtkWidget *notebook;
GtkWidget **child;
drag = gtk_drop_get_drag (drop);
notebook = g_object_get_data (drag, "gtk-notebook-drag-origin");
child = (void*) gtk_selection_data_get_data (data);
// process_widget (*child);
gtk_notebook_detach_tab (GTK_NOTEBOOK (notebook), *child);
}
If you want a notebook to accept drags from other widgets, you will have to set your own DnD code to do it.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
a child <GtkWidget>
Passed: a boolean.
whether the tab is detachable or not
Changes the tab label for child.
If #f is specified for tab-label, then the page will have
the label “page N”.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the page
Passed, or left out: a <GtkWidget>, or #f.
the tab label widget to use, or #f for default tab label
Creates a new label and sets it as the tab label for the page containing child.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the page
Passed: a string.
the label text
Sets the edge at which the tabs are drawn.
Passed: a <GtkNotebook>.
Passed: a <GtkPositionType>, or one of its
symbols.
the edge to draw the tabs at
Sets whether the notebook tab can be reordered via drag and drop or not.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
a child <GtkWidget>
Passed: a boolean.
whether the tab is reorderable or not
Connect a handler with (connect object
notebook:change-current-page handler). It is called as (handler
self page) ⇒ %return.
Emitted when the current page should be changed.
The default bindings for this signal are Ctrl+Alt+PgUp, Ctrl+Alt+PgDn, Ctrl+PgUp and Ctrl+PgDn.
Passed: a <GtkNotebook>.
Passed: a 32-bit integer.
the page index
Returned: a boolean.
whether the page was changed
Connect a handler with (connect object notebook:create-window
handler). It is called as (handler self page) ⇒ %return.
The ::create-window signal is emitted when a detachable tab is dropped on the root window.
A handler for this signal can create a window containing a notebook
where the tab will be attached. It is also responsible for
moving/resizing the window and adding the necessary properties to the
notebook (e.g. the <GtkNotebook>:group-name ).
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the tab of notebook that is being detached
Returned: a <GtkNotebook>, or #f.
a <GtkNotebook> that page should be added
to
Connect a handler with (connect object notebook:focus-tab
handler). It is called as (handler self tab) ⇒ %return.
Emitted when a tab should be focused.
Passed: a <GtkNotebook>.
Passed: a <GtkNotebookTab>.
the notebook tab
Returned: a boolean.
whether the tab has been focused
Connect a handler with (connect object notebook:move-focus-out
handler). It is called as (handler self direction).
Emitted when focus was moved out.
The default bindings for this signal are Ctrl+Tab, Ctrl+Shift+Tab, Ctrl+←, Ctrl+→, Ctrl+↑ and Ctrl+↓.
Passed: a <GtkNotebook>.
Passed: a <GtkDirectionType>.
the direction to move the focus
Connect a handler with (connect object notebook:page-added
handler). It is called as (handler self child page-num).
the ::page-added signal is emitted in the notebook right after a page is added to the notebook.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the child <GtkWidget> affected
Passed: an unsigned 32-bit integer.
the new page number for child
Connect a handler with (connect object notebook:page-removed
handler). It is called as (handler self child page-num).
the ::page-removed signal is emitted in the notebook right after a page is removed from the notebook.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the child <GtkWidget> affected
Passed: an unsigned 32-bit integer.
the child page number
Connect a handler with (connect object notebook:page-reordered
handler). It is called as (handler self child page-num).
the ::page-reordered signal is emitted in the notebook right after a page has been reordered.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the child <GtkWidget> affected
Passed: an unsigned 32-bit integer.
the new page number for child
Connect a handler with (connect object notebook:reorder-tab
handler). It is called as (handler self direction move-to-last)
⇒ %return.
Emitted when the tab should be reordered.
The default bindings for this signal are Alt+Home, Alt+End, Alt+PgUp, Alt+PgDn, Alt+←, Alt+→, Alt+↑ and Alt+↓.
Passed: a <GtkNotebook>.
Passed: a <GtkDirectionType>.
the direction to move the tab
Passed: a boolean.
whether to move to the last position
Returned: a boolean.
whether the tab was moved.
Connect a handler with (connect object notebook:select-page
handler). It is called as (handler self move-focus) ⇒ %return.
Emitted when a page should be selected.
The default binding for this signal is ␣.
Passed: a <GtkNotebook>.
Passed: a boolean.
whether to move focus
Returned: a boolean.
whether the page was selected
Connect a handler with (connect object notebook:switch-page
handler). It is called as (handler self page page-num).
Emitted when the user or a function changes the current page.
Passed: a <GtkNotebook>.
Passed: a <GtkWidget>.
the new current page
Passed: an unsigned 32-bit integer.
the index of the page