Hello folks,

I've noticed that all columns of a TableView always start with the same
width.
It ends up cutting the header (mainly when I'm using another language -
with bigger strings).
It seems that it was reported already:
http://trac.subsurface-divelog.org/ticket/788

Another point is that 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.

So, this patch will consider the title width of each section, instead of
using a static width.

All the best,
Marcos
From 612788ff510a7490b46bdef5866947110d86403c Mon Sep 17 00:00:00 2001
From: Marcos CARDINOT <[email protected]>
Date: Tue, 17 Mar 2015 17:56:52 -0300
Subject: [PATCH] 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 <[email protected]>
---
 qt-ui/tableview.cpp |    8 +++++---
 qt-ui/tableview.h   |    1 -
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/qt-ui/tableview.cpp b/qt-ui/tableview.cpp
index 78a0bce..e92f880 100644
--- a/qt-ui/tableview.cpp
+++ b/qt-ui/tableview.cpp
@@ -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,11 @@ 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();
+	if (text.isEmpty()) { // it might be an icon
+		return metrics.rm_col_width;
+	}
+	return defaultModelFontMetrics().width(text) + 4; // add small margin
 }
 
 QTableView *TableView::view()
diff --git a/qt-ui/tableview.h b/qt-ui/tableview.h
index 36eef90..f72b256 100644
--- a/qt-ui/tableview.h
+++ b/qt-ui/tableview.h
@@ -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
 	};
-- 
1.7.9.5

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to