Center text alignment in table UI cells

We can display data in a table-like form in the Blender UI with the row() and column() functions of the layout element in the Panel class, from which we inherit the custom UI panel classes.

Solution author: Dion Moult

Let’s define a custom panel class in the “Modifier” tab of the Properties area:

And register it in the Blender Python API:

In its draw() function, let’s create a 4-by-4 table with simple text fields:

After executing the code, we can see a new panel created in the object modifiers tab.

As we can see, the text in the table is not aligned to the center of the cells, but to the left.

The “alignment” parameter is usually used to align layout elements. However, if we set this option for columns:

nothing will change.

To solve this and align the text to the center of the cells, we can create another inner row in each cell and assign alignment to it.

In this case, the alignment parameter works as we need.

And we got the centered text alignment in the cells:

Full code:

0 0 votes
Article Rating
Notify of

0 Comment
Inline Feedbacks
View all comments