def assign_var_text_changed(text = None): if text == None: text = self.assign_var.text() font = self.assign_var.font() fm = QFontMetrics(font); pixelsWide = fm.width(text); # pixelsHigh = fm.height(); self.assign_var.setFixedSize(pixelsWide + 10, self.assign_var.height()) text = self.assign_var.text() text = text.replace(" ", "") self.assign_var.setText(text)
def _layout(self): """ Recalculates the layout of the of the timeline to take into account any changes that have occured """ # Calculate history left and history width max_topic_name_width = -1 for topic in self.topics: topic_width = QFontMetrics(self._topic_font).width(topic) if max_topic_name_width <= topic_width: max_topic_name_width = topic_width # Calculate font height for each topic self._topic_font_height = -1 for topic in self.topics: topic_height = QFontMetrics(self._topic_font).height() if self._topic_font_height <= topic_height: self._topic_font_height = topic_height # Update the timeline boundries new_history_left = self._margin_left + max_topic_name_width + self._topic_name_spacing new_history_width = self.scene().views()[0].size().width( ) - new_history_left - self._margin_right updated_history = (new_history_left != self._history_left or new_history_width != self._history_width) if updated_history: self._history_left = new_history_left self._history_width = new_history_width # Calculate the bounds for each topic self._history_bounds = {} y = self._history_top for topic in self.topics: datatype = self.scene().get_datatype(topic) topic_height = None if topic in self._rendered_topics: renderer = self._timeline_renderers.get(datatype) if renderer: topic_height = renderer.get_segment_height(topic) if not topic_height: topic_height = self._topic_font_height + self._topic_vertical_padding self._history_bounds[topic] = (self._history_left, y, self._history_width, topic_height) y += topic_height # new_history_bottom = max([y + h for (x, y, w, h) in self._history_bounds.values()]) - 1 new_history_bottom = max( [y + h for (_, y, _, h) in self._history_bounds.values()]) - 1 if new_history_bottom != self._history_bottom: self._history_bottom = new_history_bottom
def sizeHint(self, option, index): ''' Determines and returns the size of the text after the format. @see: U{http://www.pyside.org/docs/pyside/PySide/QtGui/QAbstractItemDelegate.html#PySide.QtGui.QAbstractItemDelegate} ''' options = QStyleOptionViewItem(option) self.initStyleOption(options, index) doc = QTextDocument() doc.setHtml(options.text) doc.setTextWidth(options.rect.width()) metric = QFontMetrics(doc.defaultFont()) return QSize(doc.idealWidth(), metric.height() + 4)
def sizeHint(self, option, index): ''' Determines and returns the size of the text after the format. @see: U{http://www.pyside.org/docs/pyside/PySide/QtGui/QAbstractItemDelegate.html#PySide.QtGui.QAbstractItemDelegate} ''' options = QStyleOptionViewItem(option) self.initStyleOption(options, index) doc = QTextDocument() doc.setHtml(options.text) doc.setTextWidth(options.rect.width()) metric = QFontMetrics(doc.defaultFont()) return QSize(doc.idealWidth(), metric.height() + 4)
def createEditor(self, parent, option, index): editor = QTextEdit(parent) highlight = syntax.PythonHighlighter(editor.document()) font = QFont("Courier") font.setFamily("Courier"); font.setStyleHint(QFont.Monospace); font.setFixedPitch(True); font.setPointSize(10); editor.setFont(font) tab_stop = 4; # 4 characters metrics = QFontMetrics(font) editor.setTabStopWidth(tab_stop * metrics.width(' ')); return editor
def _draw_major_divisions(self, painter, stamps, start_stamp, division): """ Draw black hashed vertical grid-lines showing major time divisions. :param painter: allows access to paint functions,''QPainter'' """ label_y = self._history_top - self._playhead_pointer_size[1] - 5 for stamp in stamps: x = self.map_stamp_to_x(stamp, False) label = self._get_label(division, stamp - start_stamp) label_x = x + self._major_divisions_label_indent if label_x + QFontMetrics( self._topic_font).width(label) < self.scene().width(): painter.setPen(self._default_pen) painter.setBrush(QBrush(Qt.black)) path = QPainterPath() path.addText(label_x, label_y, self._time_font, label) painter.drawPath(path) painter.setPen(self._major_division_pen) painter.drawLine( x, label_y - self._time_tick_height - self._time_font_size, x, self._history_bottom) painter.setBrush(self._default_brush) painter.setPen(self._default_pen)
def paintEvent(self, event): QSlider.paintEvent(self, event) curr_value = str(self.value()) round_value = round(float(curr_value), 4) painter = QPainter(self) painter.setPen(QPen(QtCore.Qt.white)) font_metrics = QFontMetrics(self.font()) font_width = font_metrics.boundingRect(str(round_value)).width() font_height = font_metrics.boundingRect(str(round_value)).height() rect = self.geometry() if self.orientation() == QtCore.Qt.Horizontal: horizontal_x_pos = rect.width() - font_width - 5 horizontal_y_pos = rect.height() * 0.75 painter.drawText(QtCore.QPoint(horizontal_x_pos, horizontal_y_pos), str(round_value)) self.x = self.value() else: pass painter.drawRect(rect)
def _qfont_width(self, name): return QFontMetrics(self._topic_font).width(name)