def paint(self, painter, option, index): ''' Use the QTextDokument to represent the HTML text. @see: U{http://www.pyside.org/docs/pyside/PySide/QtGui/QAbstractItemDelegate.html#PySide.QtGui.QAbstractItemDelegate} ''' options = QStyleOptionViewItem(option) self.initStyleOption(options, index) style = QApplication.style() if options.widget is None else options.widget.style() doc = QTextDocument() doc.setHtml(self.toHTML(options.text)) # doc.setTextWidth(option.rect.width()) options.text = '' style.drawControl(QStyle.CE_ItemViewItem, options, painter) ctx = QAbstractTextDocumentLayout.PaintContext() # Highlighting text if item is selected # if (optionV4.state and QStyle::State_Selected): # ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText)); textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options, options.widget) painter.save() painter.translate(QPoint(textRect.topLeft().x(), textRect.topLeft().y() - 3)) painter.setClipRect(textRect.translated(-textRect.topLeft())) doc.documentLayout().draw(painter, ctx) painter.restore()
def paintEvent(self, event): # super(QLabel, self).repaint(rect) painter = QPainter(self) # print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2", event.rect() # painter.fillRect(event.rect(), Qt.darkGray) doc = QTextDocument() highlight = syntax.PythonHighlighter(doc, is_dark = True, default = ['white']) font = self.font() # font.setFamily("Courier"); font.setStyleHint(QFont.Monospace); font.setFixedPitch(True); # font.setPointSize(self.font().pointSize()); doc.setDefaultFont(font) self.width = event.rect().width() # doc.setTextWidth(self.width()) text = self.text() doc.setPlainText(text) painter.translate(0., event.rect().center().y() - doc.size().height()/2.) doc.drawContents(painter, QRectF(event.rect())) painter.resetTransform() self.size = doc.size() # print "repainting" pass
def sizeHint(self, option, index): item = self.parent().item(index.row()) doc = QTextDocument() # highlight = syntax.PythonHighlighter(doc, is_dark = not item.has_script) font = QFont("Courier") font.setFamily("Courier"); font.setStyleHint(QFont.Monospace); font.setFixedPitch(True); font.setPointSize(self.parent().font().pointSize()); doc.setDefaultFont(font) # tab_stop = 4; # 4 characters # metrics = QFontMetrics(font) text = index.data(Qt.EditRole) text = text.replace("\t", ''.join([' '] * 4)) # print ":".join("{:02x}".format(ord(c)) for c in text) doc.setPlainText(text) doc.setDefaultStyleSheet("background-color: red;") return QSize(doc.size().width(), doc.size().height())
def _update_max_msg_count(self, txt): ''' set the count of the displayed messages on receiving the first message :param txt: text of the message, which will be added to the document :type txt: str ''' if self._blocks_in_msg is None: td = QTextDocument(txt) self._blocks_in_msg = td.blockCount() self.display.document().setMaximumBlockCount(self._blocks_in_msg * self.max_displayed_msgs)
def _update_max_msg_count(self, txt): """ set the count of the displayed messages on receiving the first message :param txt: text of the message, which will be added to the document :type txt: str """ if self._blocks_in_msg is None: td = QTextDocument(txt) self._blocks_in_msg = td.blockCount() self.display.document().setMaximumBlockCount(self._blocks_in_msg * self.max_displayed_msgs)
def paint(self, painter, option, index): ''' Use the QTextDokument to represent the HTML text. @see: U{http://www.pyside.org/docs/pyside/PySide/QtGui/QAbstractItemDelegate.html#PySide.QtGui.QAbstractItemDelegate} ''' options = QStyleOptionViewItem(option) self.initStyleOption(options, index) style = QApplication.style() if options.widget is None else options.widget.style() doc = QTextDocument() doc.setHtml(self.toHTML(options.text)) doc.setTextWidth(option.rect.width()) options.text = '' style.drawControl(QStyle.CE_ItemViewItem, options, painter) ctx = QAbstractTextDocumentLayout.PaintContext() # Highlighting text if item is selected # if (optionV4.state and QStyle::State_Selected): # ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText)); textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options, options.widget) painter.save() painter.translate(QPoint(textRect.topLeft().x(), textRect.topLeft().y() - 3)) painter.setClipRect(textRect.translated(-textRect.topLeft())) doc.documentLayout().draw(painter, ctx) painter.restore()
def sizeHint(self): if not self.is_resizable: return super(QLabel, self).sizeHint() doc = QTextDocument() # highlight = syntax.PythonHighlighter(doc, is_dark = True) font = self.font() # font.setFamily("Courier"); font.setStyleHint(QFont.Monospace); font.setFixedPitch(True); # font.setPointSize(self.font().pointSize()); doc.setDefaultFont(font) text = self.text() # doc.setTextWidth(self.width()) doc.setPlainText(text) size = QSize(doc.size().width(), doc.size().height()) if size != None: return size return super(QLabel, self).sizeHint()
def sizeHint(self, option, index): item = self.parent().item(index.row()) doc = QTextDocument() font = QFont("Courier") font.setFamily("Courier"); font.setStyleHint(QFont.Monospace); font.setFixedPitch(True); font.setPointSize(self.parent().font().pointSize()); doc.setDefaultFont(font) text = index.data(Qt.EditRole) text = text.replace("\t", ''.join([' '] * 4)) doc.setPlainText(text) doc.setDefaultStyleSheet("background-color: red;") return QSize(doc.size().width(), doc.size().height())
def paint(self, painter, option, index): is_dark = True item = self.parent().item(index.row()) if item.faulty: pen = QPen(QColor(255, 117, 117), 3) painter.setPen(pen) painter.drawRect(option.rect) elif item == self.parent().currentItem(): pen = QPen(Qt.white, 3) painter.setPen(pen) painter.drawRect(option.rect) if not item.has_script: painter.fillRect(option.rect, QColor(153, 153, 153)) else: painter.fillRect(option.rect, Qt.white) is_dark = False doc = QTextDocument() highlight = syntax.PythonHighlighter(doc, is_dark = is_dark) font = QFont("Courier") font.setFamily("Courier"); font.setStyleHint(QFont.Monospace); font.setFixedPitch(True); font.setPointSize(self.parent().font().pointSize()) doc.setDefaultFont(font) text = index.data(Qt.EditRole) text = text.replace("\t", ''.join([' '] * 4)) doc.setPlainText(text) doc.setDefaultStyleSheet("background-color: red;") painter.translate(option.rect.topLeft()) doc.drawContents(painter) painter.resetTransform()
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 paintEvent(self, event): painter = QPainter(self) doc = QTextDocument() highlight = syntax.PythonHighlighter(doc, is_dark = True, default = ['white']) font = self.font() font.setStyleHint(QFont.Monospace); font.setFixedPitch(True); doc.setDefaultFont(font) self.width = event.rect().width() text = self.text() doc.setPlainText(text) painter.translate(0., event.rect().center().y() - doc.size().height()/2.) doc.drawContents(painter, QRectF(event.rect())) painter.resetTransform() self.size = doc.size()
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): if not self.is_resizable: return super(QLabel, self).sizeHint() doc = QTextDocument() font = self.font() font.setStyleHint(QFont.Monospace); font.setFixedPitch(True); doc.setDefaultFont(font) text = self.text() doc.setPlainText(text) size = QSize(doc.size().width(), doc.size().height()) if size != None: return size return super(QLabel, self).sizeHint()
def paint(self, painter, option, index): item = self.parent().item(index.row()) # print option.backgroundBrush.color().name() is_dark = True if item.faulty: pen = QPen(QColor(255, 117, 117), 3) painter.setPen(pen) painter.drawRect(option.rect) elif item == self.parent().currentItem(): pen = QPen(Qt.white, 3) painter.setPen(pen) painter.drawRect(option.rect) if not item.has_script: painter.fillRect(option.rect, QColor(153, 153, 153)) else: painter.fillRect(option.rect, Qt.white) is_dark = False # color = item.background().color() # painter.fillRect(option.rect, color) # print dir(option) # return doc = QTextDocument() highlight = syntax.PythonHighlighter(doc, is_dark = is_dark) font = QFont("Courier") font.setFamily("Courier"); font.setStyleHint(QFont.Monospace); font.setFixedPitch(True); font.setPointSize(self.parent().font().pointSize()) doc.setDefaultFont(font) # tab_stop = 4; # 4 characters # metrics = QFontMetrics(font) text = index.data(Qt.EditRole) text = text.replace("\t", ''.join([' '] * 4)) # print ":".join("{:02x}".format(ord(c)) for c in text) doc.setPlainText(text) doc.setDefaultStyleSheet("background-color: red;") painter.translate(option.rect.topLeft()) doc.drawContents(painter) painter.resetTransform() pass