From: smbaker Date: Wed, 31 Aug 2011 16:12:10 +0000 (-0700) Subject: clip hostname/tag field at 48 characters X-Git-Tag: sface-0.1-17~1 X-Git-Url: http://git.onelab.eu/?p=sface.git;a=commitdiff_plain;h=b5b5075588b35341f7169a6956dc8f7db624fcc5;ds=sidebyside clip hostname/tag field at 48 characters --- diff --git a/sface/screens/mainscreen.py b/sface/screens/mainscreen.py index b20ae51..e6e4fb4 100644 --- a/sface/screens/mainscreen.py +++ b/sface/screens/mainscreen.py @@ -31,6 +31,9 @@ NODE_STATUS_COLUMN = 1 MEMBERSHIP_STATUS_COLUMN = 2 KIND_COLUMN = 3 +# maximum length of a name to display before clipping +NAME_MAX_LEN = 48 + def itemType(index): if index.parent().parent().isValid(): return "tag" @@ -144,15 +147,21 @@ class NodeNameDelegate(QStyledItemDelegate): def __init__(self, parent): QStyledItemDelegate.__init__(self, parent) + def displayText(self, value, locale): + data = str(QStyledItemDelegate.displayText(self, value, locale)) + if (len(data)>NAME_MAX_LEN): + data = data[:(NAME_MAX_LEN-3)] + "..." + return QString(data) + def paint(self, painter, option, index): model = index.model() + data = str(self.displayText(index.data(), QLocale())) status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent()) status_data = status_index.data().toString() fm = QFontMetrics(option.font) rect = QRect(option.rect) - data = index.data().toString() rect.setHeight(rect.height() - 2) rect.setWidth(fm.width(QString(data)) + 6) rect.setX(rect.x() + 5)