如何更改 Gtk3 StackSwitcher 控件的对齐方式
How to change Gtk3 StackSwitcher Controls' Alignment
我想使用 Gtk3 Stack Switcher 作为我的布局容器,只是想知道是否可以通过任何方式将控制按钮的对齐方式更改为 VERTICAL 因为默认情况下它们显示在一行中并且水平对齐
PS:我想改变控件本身的对齐方式而不是堆栈的内容
是的,这是可能的。 Gtk.StackSwitcher implements the Gtk.Orientable 接口并继承自 Gtk.Box
如果使用 glade,小部件常规属性选项卡中有一个组合框,允许选择方向。
您也可以使用 Gtk.Orientable method set_orientation
:
...
stack_switcher = Gtk.StackSwitcher()
stack_switcher.set_stack(stack)
stack_switcher.set_orientation(Gtk.Orientation.VERTICAL)
...
让我们使用 Python Gtk+ 3 Stack and StackSwitcher tutorial example 并更改堆栈切换器方向:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class StackWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Stack Demo")
self.set_border_width(10)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(vbox)
stack = Gtk.Stack()
stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
stack.set_transition_duration(1000)
checkbutton = Gtk.CheckButton("Click me!")
stack.add_titled(checkbutton, "check", "Check Button")
label = Gtk.Label()
label.set_markup("<big>A fancy label</big>")
stack.add_titled(label, "label", "A label")
stack_switcher = Gtk.StackSwitcher()
stack_switcher.set_stack(stack)
stack_switcher.set_orientation(Gtk.Orientation.VERTICAL)
vbox.pack_start(stack_switcher, True, True, 0)
vbox.pack_start(stack, True, True, 0)
win = StackWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
预期结果是:
垂直Gtk.StackSwitcher.
@Jose Fonte,谢谢兄弟....我接受了你的建议并尝试使用它,不过过了一会儿,我发现了一些更容易修复我的 problem.A Gtk.StackSideBar.所以我最终使用了它,因为这正是我想要的
我想使用 Gtk3 Stack Switcher 作为我的布局容器,只是想知道是否可以通过任何方式将控制按钮的对齐方式更改为 VERTICAL 因为默认情况下它们显示在一行中并且水平对齐
PS:我想改变控件本身的对齐方式而不是堆栈的内容
是的,这是可能的。 Gtk.StackSwitcher implements the Gtk.Orientable 接口并继承自 Gtk.Box
如果使用 glade,小部件常规属性选项卡中有一个组合框,允许选择方向。
您也可以使用 Gtk.Orientable method set_orientation
:
...
stack_switcher = Gtk.StackSwitcher()
stack_switcher.set_stack(stack)
stack_switcher.set_orientation(Gtk.Orientation.VERTICAL)
...
让我们使用 Python Gtk+ 3 Stack and StackSwitcher tutorial example 并更改堆栈切换器方向:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class StackWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Stack Demo")
self.set_border_width(10)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(vbox)
stack = Gtk.Stack()
stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
stack.set_transition_duration(1000)
checkbutton = Gtk.CheckButton("Click me!")
stack.add_titled(checkbutton, "check", "Check Button")
label = Gtk.Label()
label.set_markup("<big>A fancy label</big>")
stack.add_titled(label, "label", "A label")
stack_switcher = Gtk.StackSwitcher()
stack_switcher.set_stack(stack)
stack_switcher.set_orientation(Gtk.Orientation.VERTICAL)
vbox.pack_start(stack_switcher, True, True, 0)
vbox.pack_start(stack, True, True, 0)
win = StackWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
预期结果是:
垂直Gtk.StackSwitcher.
@Jose Fonte,谢谢兄弟....我接受了你的建议并尝试使用它,不过过了一会儿,我发现了一些更容易修复我的 problem.A Gtk.StackSideBar.所以我最终使用了它,因为这正是我想要的