1
$\begingroup$

Is there a way to vertically align this too, meaning to remove the space between the rows and make the elements connect?

Vertical align

import bpy

from bpy.props import *
from bpy.types import Operator, Panel

bpy.types.Scene.test = IntProperty()
bpy.types.Scene.test2 = IntProperty()


class LayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "Layout Demo"
    bl_idname = "SCENE_PT_layout"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        layout = self.layout

        scene = context.scene

        # Create a simple row.
        layout.label(text=" Simple Row:")

        row = layout.row(align=True)
        split = row.split(align=True)
        split.prop(scene, "test")
        row = layout.row(align=True)
        split = row.split(align=True,  percentage=0.7)
        col = split.column(align=True)
        col.prop(scene, "test2")
        col = split.column(align=True)
        col.operator("render.render")



def register():
    bpy.utils.register_class(LayoutDemoPanel)


def unregister():
    bpy.utils.unregister_class(LayoutDemoPanel)


if __name__ == "__main__":
    register()
$\endgroup$
2
  • $\begingroup$ No, as it is: row 1 = prop - row 2 = prop, operator but remove the space between row 1 and row 2 $\endgroup$
    – MSchmits
    Jan 16, 2016 at 8:16
  • $\begingroup$ you might have to draw schematic or manipulate an image to show us what you hope to achieve -- this makes suggesting the right code less trial and error. $\endgroup$
    – zeffii
    Jan 16, 2016 at 8:35

2 Answers 2

4
$\begingroup$

You understand the formatting wrong - see this with comments:

        # simple label
        layout.label(text=" Simple Row:")

        # create column to be able to merge vertically with align=true on a column
        col = layout.column(align=True)

        # create test row inside the column
        row = col.row(align=True)
        row.prop(scene, "test")
        # even if there is only 1 item in this row it needs aligning because otherwise the column align would'n work

        # create the test2 row within column and allow horizontal merge with align=true on this row
        row = col.row(align=True)
        # we don't want to put anything else on this row other than the 'split' item
        split = row.split(align=True, percentage=0.7)

        # put 2 things inside the split
        split.prop(scene, "test2")
        split.operator("render.render")

enter image description here

You can also make the button span across 2 rows if you order the elements in a different way:

        # simple label
        layout.label(text=" Simple Row:")

        # start with a splitted row - we dont want to split the whole layout if something
        # needs to be added after these elements
        row = layout.row(align=True)
        split = row.split(align=True, percentage=0.7)

        # put 2 columns inside the split
        colA = split.column(align=True)
        colB = split.column(align=True)

        # fill first column with props
        colA.prop(scene, "test")
        colA.prop(scene, "test2")

        # put a row into second column
        row = colB.row(align=True)
        # adjust the row's Y scale
        row.scale_y = 2
        row.operator("render.render")

enter image description here

$\endgroup$
2
$\begingroup$

or perhaps:

def draw(self, context):
    layout = self.layout
    scene = context.scene
    layout.label(text=" Simple Row:")

    row = layout.row(align=True)
    split = row.split(percentage=0.7)

    left_side = split.column(align=True)
    left_side.prop(scene, "test")
    left_side.prop(scene, "test2")

    right_side = split.column()
    right_side.operator("render.render")

enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .