Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add padding to QTreeView Columns

Tags:

qt

pyside

I've added a left and right padding to the header of the QTreeView using this QSS code:

QHeaderView::section{padding:7px 15px}

But the content of the columns is not aligned anymore with the headers.

unaligned QTreeView columns with headers title

How can I add a padding of 15px ( like in the header ) to the columns' content?

Edit: For some reasons I use delegates to draw the content of the QTreeView, that's why styling the QTreeView::item doesn't work ( like @svlasov suggested ).

painter.translate(15, 0) seems to fix this issue, but a weird effect appears when I select a row: the selection is not continuous.

enter image description here

like image 598
Ghilas BELHADJ Avatar asked Oct 24 '25 13:10

Ghilas BELHADJ


1 Answers

Something like this:

QTreeView::item {  border: 0px;  padding: 0 15px; }
like image 89
svlasov Avatar answered Oct 27 '25 11:10

svlasov