Gtk.Viewport
Gtk.Viewport — An adapter which makes widgets scrollable
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
╰── Gtk.Bin
╰── Gtk.Viewport
See also:
Gtk.ScrolledWindow, Gtk.Adjustment
Functions:
- new
(hadjustment:Gtk.Adjustment=None, vadjustment:Gtk.Adjustment=None) -> Gtk.Widget
- get_hadjustment
(self) -> Gtk.Adjustment
- get_vadjustment
(self) -> Gtk.Adjustment
- set_hadjustment
(self, adjustment:Gtk.Adjustment=None)
- set_vadjustment
(self, adjustment:Gtk.Adjustment=None)
- set_shadow_type
(self, type:Gtk.ShadowType)
- get_shadow_type
(self) -> Gtk.ShadowType
- get_bin_window
(self) -> Gdk.Window
- get_view_window
(self) -> Gdk.Window
Description:
The Gtk.Viewport
widget acts as an adaptor class, implementing scrollability for child widgets that lack their own scrolling capabilities. Use Gtk.Viewport
to scroll child widgets such as Gtk.Grid, GtkBox, and so on.
If a widget has native scrolling abilities, such as Gtk.TextView, Gtk.TreeView or Gtk.IconView, it can be added to a Gtk.ScrolledWindow with Gtk.Container::add()
. If a widget does not, you must first add the widget to a Gtk.Viewport
, then add the viewport to the scrolled window.
Gtk.Container::add()
does this automatically if a child that does not implement GtkScrollable is added to a Gtk.ScrolledWindow, so you can ignore the presence of the viewport.
The Gtk.Viewport
will start scrolling content only if allocated less than the child widget’s minimum size in a given orientation.
Function Details:
new()
new (hadjustment:Gtk.Adjustment=None, vadjustment:Gtk.Adjustment=None) -> Gtk.Widget
Creates a new Gtk.Viewport
with the given adjustments, or with defaultadjustments if none are given.
- Returns: a new Gtk.Viewport
get_hadjustment()
get_hadjustment (self) -> Gtk.Adjustment
Gtk.Viewport:get_hadjustment
has been deprecated since version 3.0 and should not be used in newly-written code.
Use `Gtk.Scrollable:get_hadjustment
()`
Returns the horizontal adjustment of the viewport.
- Returns:
the horizontal adjustment of
viewport
.
get_vadjustment()
get_vadjustment (self) -> Gtk.Adjustment
Gtk.Viewport:get_vadjustment
has been deprecated since version 3.0 and should not be used in newly-written code.
Use `Gtk.Scrollable:get_vadjustment
()`
Returns the vertical adjustment of the viewport.
- Returns:
the vertical adjustment of
viewport
.
set_hadjustment()
set_hadjustment (self, adjustment:Gtk.Adjustment=None)
Gtk.Viewport:set_hadjustment
has been deprecated since version 3.0 and should not be used in newly-written code.
Use `Gtk.Scrollable:set_hadjustment
()`
Sets the horizontal adjustment of the viewport.
set_vadjustment()
set_vadjustment (self, adjustment:Gtk.Adjustment=None)
Gtk.Viewport:set_vadjustment
has been deprecated since version 3.0 and should not be used in newly-written code.
Use `Gtk.Scrollable:set_vadjustment
()`
Sets the vertical adjustment of the viewport.
set_shadow_type()
set_shadow_type (self, type:Gtk.ShadowType)
Sets the shadow type of the viewport.
get_shadow_type()
get_shadow_type (self) -> Gtk.ShadowType
Gets the shadow type of the Gtk.Viewport
. SeeGtk.Viewport:set_shadow_type()
.
- Returns: the shadow type
get_bin_window()
get_bin_window (self) -> Gdk.Window
Gets the bin window of the Gtk.Viewport
.
Returns: a GdkWindow.
Since: 2.20
get_view_window()
get_view_window (self) -> Gdk.Window
Gets the view window of the Gtk.Viewport
.
Returns: a GdkWindow.
Since: 2.22
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Viewport(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_default_size(-1, 200)
self.connect("destroy", Gtk.main_quit)
scrolledwindow = Gtk.ScrolledWindow()
self.add(scrolledwindow)
hadjustment = Gtk.Adjustment()
vadjustment = Gtk.Adjustment()
viewport = Gtk.Viewport(hadjustment, vadjustment)
scrolledwindow.add(viewport)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
viewport.add(box)
for i in range(1, 16):
button = Gtk.Button(label="Button %s" % i)
box.pack_start(button, True, True, 0)
window = Viewport()
window.show_all()
Gtk.main()