silverhash
silverhash

Reputation: 919

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

PS:I want to change the alignment of the controls themselves not the contents of the stack

Upvotes: 2

Views: 1283

Answers (2)

silverhash
silverhash

Reputation: 919

@Jose Fonte,thanks bro....i took your advice and tried to use it,After a while though,I descovered something else that was way easier to fix my problem.A Gtk.StackSideBar.So i ended up using that as this is exactly what i was after

Upvotes: 1

José Fonte
José Fonte

Reputation: 4104

Yes, it is possible. Gtk.StackSwitcher implements the Gtk.Orientable interface and inherits from Gtk.Box

If using glade, there is a combobox in the widget General attributes tab which allows choosing the orientation.

You can also do it programmatically, using the Gtk.Orientable method 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:

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:

enter image description here

a vertical Gtk.StackSwitcher.

Upvotes: 1

Related Questions