Exemple #1
0
 def updateImage(self, text):
     font = Qt.QFont(self.label.font())
     font.setPointSizeF(50)
     metrics = Qt.QFontMetricsF(font)
     #text = str(self.tr('Swipe your card'))
     rect = metrics.boundingRect(text)
     position = -rect.topLeft()
     pixmap = Qt.QPixmap(rect.width(), rect.height())
     color = QtGui.QColor.fromRgb(255, 255, 255, 255)
     pixmap.fill(color)
     painter = Qt.QPainter()
     painter.begin(pixmap)
     painter.setFont(font)
     painter.drawText(position, text)
     painter.end()
     self.label.setPixmap(pixmap)
     self.show()
Exemple #2
0
    def updateImage(self):

        font = Qt.QFont(self.fontComboBox.currentFont())
        font.setPointSizeF(self.sizeSpinBox.value())
        metrics = Qt.QFontMetricsF(font)

        text = str(self.lineEdit.text())
        if not text:
            return

        rect = metrics.boundingRect(text)
        position = -rect.topLeft()

        pixmap = Qt.QPixmap(rect.width(), rect.height())
        color = QtGui.QColor.fromRgb(255, 255, 255, 255)
        pixmap.fill(color)

        painter = Qt.QPainter()
        painter.begin(pixmap)
        painter.setFont(font)
        painter.drawText(position, text)
        painter.end()

        self.label.setPixmap(pixmap)