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): 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() # 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 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 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): 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