TableView - improving the column width calculation

Even that most (or all) tables have the remove button at the section 0, the method defaultColumnWidth should not assume that it will always be true.

This patch will consider the title width of each section, instead of using a static width (which cause problems when the language is not en).

Signed-off-by: Marcos Cardinot <mcardinot@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Marcos CARDINOT 2015-03-17 17:56:52 -03:00 committed by Dirk Hohndel
parent b31e192da1
commit d500f56d6f
2 changed files with 2 additions and 4 deletions

View file

@ -12,11 +12,9 @@ TableView::TableView(QWidget *parent) : QGroupBox(parent)
QFontMetrics fm(defaultModelFont());
int text_ht = fm.height();
int text_em = fm.width('m');
metrics.icon = &defaultIconMetrics();
metrics.col_width = 7*text_em;
metrics.rm_col_width = metrics.icon->sz_small + 2*metrics.icon->spacing;
metrics.header_ht = text_ht + 10; // TODO DPI
@ -138,7 +136,8 @@ void TableView::edit(const QModelIndex &index)
int TableView::defaultColumnWidth(int col)
{
return col == CylindersModel::REMOVE ? metrics.rm_col_width : metrics.col_width;
QString text = ui.tableView->model()->headerData(col, Qt::Horizontal).toString();
return text.isEmpty() ? metrics.rm_col_width : defaultModelFontMetrics().width(text) + 4; // add small margin
}
QTableView *TableView::view()

View file

@ -21,7 +21,6 @@ class TableView : public QGroupBox {
struct TableMetrics {
const IconMetrics* icon; // icon metrics
int col_width; // generic column width
int rm_col_width; // column width of REMOVE column
int header_ht; // height of the header
};