From 58ac3b8f86549ca9f373b3ef2a54fe2d71667719 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 19 Oct 2014 16:15:21 +0200 Subject: Fix tableview margins The previous hard-coded solution for GTK+ didn't work on HiDPI, and a comment hinted that even on Mac OS X it might need tuning. Find a more generic solution that should work regardless of platform and style, based purely on the geometries reported by the style itself. Signed-off-by: Giuseppe Bilotta Signed-off-by: Dirk Hohndel --- qt-ui/tableview.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/tableview.cpp b/qt-ui/tableview.cpp index 423fcc766..8232fb604 100644 --- a/qt-ui/tableview.cpp +++ b/qt-ui/tableview.cpp @@ -24,11 +24,31 @@ TableView::TableView(QWidget *parent) : QGroupBox(parent) metrics.rm_col_width = metrics.icon->sz_small + 2*metrics.icon->spacing; metrics.header_ht = text_ht + 10; // TODO DPI - /* There`s mostly a need for a Mac fix here too. */ - if (qApp->style()->objectName() == "gtk+") - layout()->setContentsMargins(0, 9, 0, 0); - else - layout()->setContentsMargins(0, 0, 0, 0); + /* We want to get rid of the margin around the table, but + * we must be careful with some styles (e.g. GTK+) where the top + * margin is actually used to hold the label. We thus check the + * rectangles for the label and contents to make sure they do not + * overlap, and adjust the top contentsMargin accordingly + */ + + // start by setting all the margins at zero + QMargins margins; + + // grab the label and contents dimensions and positions + QStyleOptionGroupBox option; + initStyleOption(&option); + QRect labelRect = style()->subControlRect(QStyle::CC_GroupBox, &option, QStyle::SC_GroupBoxLabel, this); + QRect contentsRect = style()->subControlRect(QStyle::CC_GroupBox, &option, QStyle::SC_GroupBoxContents, this); + + /* we need to ensure that the bottom of the label is higher + * than the top of the contents */ + int delta = contentsRect.top() - labelRect.bottom(); + const int min_gap = metrics.icon->spacing; + if (delta <= min_gap) { + margins.setTop(min_gap - delta); + } + layout()->setContentsMargins(margins); + QIcon plusIcon(":plus"); plusBtn = new QPushButton(plusIcon, QString(), this); plusBtn->setFlat(true); -- cgit v1.2.3-70-g09d2