Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce a table view's cell padding or margin

I'm using a Table View.
I'd like to remove the cell padding (or margin) so I can squeeze more cells in less space. How can this be achieved?
The cells size is set to 32 pixels on QT designer, if I set it smaller, the cells contents don't show and an ellipsis appears. (...)

alt text http://img692.imageshack.us/img692/3484/tableviewpng.png

like image 557
Petruza Avatar asked Jun 24 '10 18:06

Petruza


People also ask

How do I reduce cell padding in HTML?

To set cell padding in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property padding.

How do I change the margins in a cell table?

Change the margins in a cell Select the cells you want to change. Right-click the table, and then click Format Table. In the Format Table dialog box, click the Cell Properties tab. Under Text Box Margins, enter the margins you want.


1 Answers

Recommend you to use this code:

QTableView *tableView = new QTableView(this);

tableView->setModel(model_);

QHeaderView *verticalHeader = tableView->verticalHeader();
verticalHeader->setDefaultSectionSize(verticalHeader->fontMetrics().height()+2);

// or ...

QHeaderView *horizontalHeader = tableView->horizontalHeader();
horizontalHeader->setStretchLastSection(false);
horizontalHeader->resizeSection(/* your personal height */);

PS: Also I have noticed, that if in tableView too much rows or columns, for example about 20K rows or more, this functions resizeSection() may be too slow...

like image 186
mosg Avatar answered Sep 22 '22 14:09

mosg