I have a checkbox in a panel. I have assigned a toggle hotkey to it. But when i press the hotkey then the checkbox does not change its state until you move with the mouse over the checkbox.

How can i force a redraw at the checkbox when i press the hotkey?

To reproduce, add keymap item with wm.context_toggle and the Context Attribute window_manager.deselect_bool

The script:

´╗┐import bpy
from bpy.props import BoolProperty

class LayoutDemoPanel(bpy.types.Panel):
    bl_label = "Demo Panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'

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

        wm = context.window_manager # Our bool is in the windows_manager
        layout.prop(wm, "deselect_bool") # Our checkbox

def register():
    bpy.types.WindowManager.deselect_bool = bpy.props.BoolProperty(
    name="Checkbox", description="A checkbox", default = False)

def unregister():
    del bpy.types.WindowManager.deselect_bool # Unregister our flag when unregister.

if __name__ == "__main__":
  • $\begingroup$ Tagging the area to force a redraw via context.area.tag_redraw() should work. Here is an example: gist.github.com/p2or/8a37617c4565e4ff143b736a0e4a1660 $\endgroup$ – p2or Jul 24 '16 at 14:10
  • $\begingroup$ Also see my answer to your last question: blender.stackexchange.com/a/58534/3710 $\endgroup$ – p2or Jul 24 '16 at 15:20
  • $\begingroup$ Thank you very much for this example. I have to study this. When i install it as an addon then it works. But when i run it as a script then the panel doesn't show. But at least i have a working example now :) $\endgroup$ – Tiles Jul 24 '16 at 16:11
  • $\begingroup$ You are welcome! Can't confirm - running this from the text editor also works here without errors in Blender 2.77a on Linux. You can try to remove the bl_info first, but let me know if there is an error... In order to dive in, you can read: blender.stackexchange.com/questions/57306/… (I hope that's helpful at least). $\endgroup$ – p2or Jul 24 '16 at 16:39
  • $\begingroup$ To make the checkbox update with pressing the hotkey is a follow up problem of the thread you mention here. I thought it is better to make a separate thread for the separated problem. But we could also delete this one since the follower is solved in the original thread. $\endgroup$ – Tiles Jul 26 '16 at 7:12

Browse other questions tagged or ask your own question.