简体   繁体   English

如何更改 Gtk3 StackSwitcher 控件的对齐方式

[英]How to change Gtk3 StackSwitcher Controls' Alignment

I'd like to use a Gtk3 Stack Switcher as my layout container and was just wondering if it is,by any means,possible to change the control buttons' alignment to say VERTICAL because by default they are shown in a row and they are horizontally aligned我想使用 Gtk3 Stack Switcher 作为我的布局容器,只是想知道是否可以通过任何方式将控制按钮的对齐方式更改为VERTICAL因为默认情况下它们显示在一行中并且它们是水平的对齐

PS:I want to change the alignment of the controls themselves not the contents of the stack PS:我想改变控件本身的对齐方式而不是堆栈的内容

Yes, it is possible.对的,这是可能的。 Gtk.StackSwitcher implements the Gtk.Orientable interface and inherits from Gtk.Box Gtk.StackSwitcher实现了Gtk.Orientable接口并继承自 Gtk.Box

If using glade , there is a combobox in the widget General attributes tab which allows choosing the orientation.如果使用Glade ,小部件常规属性选项卡中有一个组合框,可以选择方向。

You can also do it programmatically, using the Gtk.Orientable method set_orientation :您也可以使用Gtk.Orientable方法set_orientation编程方式set_orientation

...    
stack_switcher = Gtk.StackSwitcher()
stack_switcher.set_stack(stack)
stack_switcher.set_orientation(Gtk.Orientation.VERTICAL)
...

Let's take the Python Gtk+ 3 Stack and StackSwitcher tutorial example and change the stack switcher orientation:让我们以 Python Gtk+ 3 Stack 和 StackSwitcher 教程示例并更改堆栈切换器方向:

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()

The expected result is:预期的结果是:

在此处输入图片说明

a vertical Gtk.StackSwitcher.一个垂直的 Gtk.StackSwitcher。

@Jose Fonte,谢谢兄弟......我接受了你的建议并尝试使用它,但过了一会儿,我发现了其他更容易解决我的问题的东西。一个Gtk.StackSideBar 。所以我最终使用它作为这正是我所追求的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM