Gtk.ScrolledWindow
Gtk.ScrolledWindow滚动布局
继承关系
Gtk.ScrolledWindow是Gtk.Window的直接子类
Methods
方法修饰词 | 方法名及参数 |
---|---|
static | new (hadjustment, vadjustment) |
add_with_viewport (child) | |
get_capture_button_press () | |
get_hadjustment () | |
get_hscrollbar () | |
get_kinetic_scrolling () | |
get_min_content_height () | |
get_min_content_width () | |
get_overlay_scrolling () | |
get_placement () | |
get_policy () | |
get_shadow_type () | |
get_vadjustment () | |
get_vscrollbar () | |
set_capture_button_press (capture_button_press) | |
set_hadjustment (hadjustment) | |
set_kinetic_scrolling (kinetic_scrolling) | |
set_min_content_height (height) | |
set_min_content_width (width) | |
set_overlay_scrolling (overlay_scrolling) | |
set_placement (window_placement) | |
set_policy (hscrollbar_policy, vscrollbar_policy) | |
set_shadow_type (type) | |
set_vadjustment (vadjustment) | |
unset_placement () |
Virtual Methods
do_move_focus_out (direction) |
do_scroll_child (scroll, horizontal) |
Properties
Name | Type | Flags | Short Description |
---|---|---|---|
hadjustment | Gtk.Adjustment | r/w/c | 水平方向的 Gtk.Adjustment |
hscrollbar-policy | Gtk.PolicyType | r/w/en | 水平滚动条显示方式 |
kinetic-scrolling | bool | r/w/en | Kinetic scrolling mode. |
min-content-height | int | r/w/en | The minimum height that the scrolled window will allocate to its content |
min-content-width | int | r/w/en | The minimum width that the scrolled window will allocate to its content |
overlay-scrolling | bool | r/w/en | Overlay scrolling mode |
shadow-type | Gtk.ShadowType | r/w/en | 阴影样式 |
vadjustment | Gtk.Adjustment | r/w/c | 垂直方向Gtk.Adjustment |
vscrollbar-policy | Gtk.PolicyType | r/w/en | 垂直滚动条显示方式 |
window-placement | Gtk.CornerType | r/w/en | Where the contents are located with respect to the scrollbars. |
window-placement-set | bool | r/w/en | Whether “window-placement” should be used to determine the location of the contents with respect to the scrollbars. deprecated |
Signals
Name | Short Description |
---|---|
edge-overshot | The ::edge-overshot signal is emitted whenever user initiated scrolling makes the scrolledwindow firmly surpass (ie. |
edge-reached | The ::edge-reached signal is emitted whenever user-initiated scrolling makes the scrolledwindow exactly reaches the lower or upper limits defined by the adjustment in that orientation. |
move-focus-out | The ::move-focus-out signal is a keybinding signal which gets emitted when focus is moved away from the scrolled window by a keybinding. |
scroll-child | The ::scroll-child signal is a keybinding signal which gets emitted when a keybinding that scrolls is pressed. |
例子
代码:
#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/11
# section 055
#
# author: xiaosanyu
# website: yuxiaosan.tk \
# http://blog.youkuaiyun.com/a87b01c14
# created: 16/7/11
TITLE = "ScrolledWindow"
DESCRIPTION = """
Gtk.ScrolledWindow is a Gtk.Bin subclass: it’s a container the accepts a single child widget.
Gtk.ScrolledWindow adds scrollbars to the child widget and optionally draws a beveled frame around the child widget.
The scrolled window can work in two ways. Some widgets have native scrolling support;
these widgets implement the Gtk.Scrollable interface. Widgets with native scroll support include Gtk.TreeView, Gtk.TextView, and Gtk.Layout.
For widgets that lack native scrolling support, 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, Gtk.Box, and so on.
If a widget has native scrolling abilities, it can be added to the Gtk.ScrolledWindow
with Gtk.Container.add(). If a widget does not, you must first add the widget to a Gtk.Viewport,
then add the Gtk.Viewport to the scrolled window. Gtk.Container.add() will do this for you for widgets
that don’t implement Gtk.Scrollable natively, so you can ignore the presence of the viewport
"""
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
HEIGHT = 20
NUM = 100
class ScrolledWindow(Gtk.Window):
def __init__(self):
super(ScrolledWindow, self).__init__(title="ScrolledWindow Demo")
self.set_size_request(200, 200)
self.layout = Gtk.Layout.new(None, None)
# important Sets the size of the scrollable area of the layout.
self.layout.set_size(200, NUM * HEIGHT)
self.sw = Gtk.ScrolledWindow()
self.sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
self.sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.sw.add(self.layout)
for i in range(NUM):
self.layout.put(Gtk.Label("label" + str(i)), 20, HEIGHT * i)
self.add(self.sw)
def main():
win = ScrolledWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == "__main__":
main()
代码下载地址:http://download.youkuaiyun.com/detail/a87b01c14/9594728