1
$\begingroup$

I’m trying to customize a panel using python in Blender 4.1, and I want to align an icon to the right side of the panel header. (like this)

enter image description here

I’ve tried a few approaches, but I can’t seem to get it right. Could someone please provide an example on how to achieve this? Would be very helpful, thanks a lot !

$\endgroup$

1 Answer 1

2
$\begingroup$

use draw_header_preset()

https://docs.blender.org/api/current/bpy.types.Panel.html#bpy.types.Panel.draw_header_preset

import bpy


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Test"
    
    def draw_header_preset(self, context):
        layout = self.layout
        layout.label(text="", icon="INFO")

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


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


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


if __name__ == "__main__":
    register()
$\endgroup$
1
  • $\begingroup$ Thank you very much, it works! That was my case, by the way: def draw_header(self, context): layout = self.layout layout.prop(context.scene.my_tool, "showhide_shake", text="") def draw_header_preset(self, context): layout = self.layout infoRow = layout.row(align=True) infoRow.operator("custom.show_message", icon="INFO", text="", emboss=False) $\endgroup$
    – VxQtW-1
    Commented May 25 at 10:32

You must log in to answer this question.

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