Is it Python, from the space_view3d.py or related python file, or the deeper C/C++ code that allows alignment of the header elements at the top of the 3D Viewport? You can see space after the Object dropdown, and after the Proportional editing button. What makes it stretchy or otherwise move with the rest of Blender? enter image description here

I'm attempting to add a camera options dropdown to the top header within the 3D viewport, and looking to align it using python. As of right now, if I shrink/expand Blender along its width, the default header items stretch/adjust to fit the screen properly, but my item follows its own, erroneous alignment. How can I make it stretch/justify/align with the other items, and possibly have it end up by the "Object" Button, or another specific area within the header?

Image shows the item highlighted in Blue on the right.

enter image description here

2nd image shows item partially hidden behind other Header items after the Blender app was shrunk via the width. enter image description here

Drawing inspiration from the space_view3d.py file, I have this so far for the draw:

import bpy

from bpy.utils import register_class, unregister_class

from bpy.types import (
class VIEW3D_HT_cam2header(Header):    
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'HEADER'
    bl_label = "Camera"

    def draw(self, context):

        layout = self.layout

        view = context.space_data

        layout.scale_x = 1
        layout.scale_y = 1
        obj = context.object
        view = context.space_data
        scene = context.scene

#   Camera popover.
        row = layout.row(align=True)
        row.prop(view, "lock_camera", text="", toggle=True, icon='OUTLINER_DATA_CAMERA')
        sub = row.row(align=True)
        sub.ui_units_x = 1
        sub.scale_x = 1
        sub.active = view.lock_camera

        layout.label(text="", icon='RNDCURVE')

class VIEW3D_PT_cam(Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'HEADER'
    bl_label = "Camera Tools"

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

        scene = context.scene
        view = context.space_data
        row = layout.row()

        row = layout.row()
#       row.operator('view3d.view_camera' , text = "", icon = "OUTLINER_OB_CAMERA")

# Class list to register
_classes = [

def register():
    for cls in _classes:

def unregister():
    for cls in _classes:

if __name__ == "__main__":

and I'm just using a row.prop that calls a Panel for the dropdown. Added the full code.

So my question is two parted:

  1. Are the menu items in the header being positioned via python
  2. and if so, how can I get my code to align a new menu item and make it move/stretch with the rest of them?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.