def minimumLabelWidth(self): """ Returns the minimum label width required on this renderers font size. :param labels | [<str>, ..] """ min_w = 0 metrics = QFontMetrics(self.labelFont()) for label in self.labels(): min_w = max(min_w, metrics.width(label)) return max(self._minimumLabelWidth, min_w + self.horizontalLabelPadding())
def setText( self, text ): """ Sets the text for this item and resizes it to fit the text and the remove button. :param text | <str> """ super(XMultiTagItem, self).setText(text) metrics = QFontMetrics(self.font()) hint = QSize(metrics.width(text) + 24, 18) self.setSizeHint(hint)
def setText(self, text): """ Sets the text for this item and resizes it to fit the text and the remove button. :param text | <str> """ super(XMultiTagItem, self).setText(text) metrics = QFontMetrics(self.font()) hint = QSize(metrics.width(text) + 24, 18) self.setSizeHint(hint)
def adjustMinimumWidth( self ): """ Updates the minimum width for this menu based on the font metrics \ for its title (if its shown). This method is called automatically \ when the menu is shown. """ if not self.showTitle(): return metrics = QFontMetrics(self.font()) width = metrics.width(self.title()) + 20 if self.minimumWidth() < width: self.setMinimumWidth(width)
def adjustMinimumWidth(self): """ Updates the minimum width for this menu based on the font metrics \ for its title (if its shown). This method is called automatically \ when the menu is shown. """ if not self.showTitle(): return metrics = QFontMetrics(self.font()) width = metrics.width(self.title()) + 20 if self.minimumWidth() < width: self.setMinimumWidth(width)
def updateEditorGeometry(self, editor, option, index): super(ColumnDelegate, self).updateEditorGeometry(editor, option, index) keys = map(lambda x: nativestring(editor.itemText(x)), range(editor.count())) longest = max(map(lambda x: (len(x), x), keys))[1] metrics = QFontMetrics(editor.font()) width = metrics.width(longest) + 30 tree = self.parent() item = tree.itemFromIndex(index) rect = tree.visualItemRect(item) if (index.column() == 0): width += rect.x() editor.resize(width, rect.height())
def updateEditorGeometry( self, editor, option, index ): super(ColumnDelegate, self).updateEditorGeometry(editor, option, index) keys = map(lambda x: nativestring(editor.itemText(x)), range(editor.count())) longest = max(map(lambda x: (len(x), x), keys))[1] metrics = QFontMetrics(editor.font()) width = metrics.width(longest) + 30 tree = self.parent() item = tree.itemFromIndex(index) rect = tree.visualItemRect(item) if ( index.column() == 0 ): width += rect.x() editor.resize(width, rect.height())
def maxNotchSize( self, orientation ): """ Returns the maximum size for this ruler based on its notches and the given orientation. :param orientation | <Qt.Orientation> :return <int> """ metrics = QFontMetrics(QApplication.font()) if orientation == Qt.Vertical: notch = '' for n in self.notches(): if len(nativestring(n)) > len(nativestring(notch)): notch = nativestring(n) return metrics.width(notch) else: return metrics.height()
def maxNotchSize(self, orientation): """ Returns the maximum size for this ruler based on its notches and the given orientation. :param orientation | <Qt.Orientation> :return <int> """ metrics = QFontMetrics(QApplication.font()) if orientation == Qt.Vertical: notch = '' for n in self.notches(): if len(nativestring(n)) > len(nativestring(notch)): notch = nativestring(n) return metrics.width(notch) else: return metrics.height()