Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the padding of QTableView cells through CSS?

Tags:

c++

css

qt

Is it possible to define the padding of QTableView cells? I would expect this to be possible using CSS stylesheets, but the documentation does not describe a method to do this.

The following stylesheet does not have the desired effect:

QTableView {
  padding: 5px;
}

as it influences the padding property of the widget as a whole, not of the individual cells.

like image 919
Ton van den Heuvel Avatar asked Nov 14 '09 10:11

Ton van den Heuvel


2 Answers

I managed to get it to work using the ::item sub-control specifier as follows:

QTableView::item
{
  border: 0px;
  padding: 5px;
}

Note that setting the border property here is necessary to get this to work. Also, this is not super ideal, since it only seems to influence the left and right padding of the QTableView cell. I can live with it for now though.

like image 133
Ton van den Heuvel Avatar answered Nov 01 '22 02:11

Ton van den Heuvel


I know this is an old question but I've been struggling with this recently.

I found out that by setting

tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);

the padding set in your CSS will then be applied to the top and bottom of the cell, too!

like image 22
ltr6 Avatar answered Nov 01 '22 03:11

ltr6