コード例 #1
0
def encode_image(image: QImage) -> str:
    image_bytes = QByteArray()
    buffer = QBuffer(image_bytes)
    buffer.open(QIODevice.WriteOnly)

    # writes pixmap into bytes in PNG format
    image.save(buffer, "PNG")  # type: ignore
    encoded_bytes = image_bytes.toBase64()
    codec = QTextCodec.codecForName(b"UTF-8")
    encoded_string = codec.toUnicode(encoded_bytes)
    return encoded_string
コード例 #2
0
ファイル: corssing2.py プロジェクト: demolice/Projects
    def __init__(self, model, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.model = model

        # Inicializace socketu
        self.socket = QTcpSocket(self)
        self.socket.readyRead.connect(self.read)
        self.socket.stateChanged.connect(self.socketStateChanged)

        # Příprava pro čtení dat
        self.readBuffer = QByteArray()
        self.textCodec = QTextCodec.codecForName("UTF-8")
コード例 #3
0
            100 - percentGreen, 1)
        self.btnYellow.text = "Yellow\n%0.1f%%" % round(100 - percentBlue, 1)

        self.btnRed.text = "Red\n%0.1f%%" % round(percentRed, 1)
        self.btnGreen.text = "Green\n%0.1f%%" % round(percentGreen, 1)
        self.btnBlue.text = "Blue\n%0.1f%%" % round(percentBlue, 1)

    def buttonClicked(self) -> None:
        btn: ColorButton = self.sender()
        if btn == self.btnPanelFader:
            self.stackedWidget.setCurrentIndex(0)
        elif btn == self.btnPanelHSB:
            self.stackedWidget.setCurrentIndex(1)
        elif btn == self.btnPanelBtn:
            self.stackedWidget.setCurrentIndex(2)


if __name__ == '__main__':
    import sys
    from PySide2.QtCore import QTextCodec
    from PySide2.QtWidgets import QApplication

    app = QApplication()
    app.setFont(QFont("Microsoft Yahei", 9))
    codec: QTextCodec = QTextCodec.codecForName(b"utf-8")
    QTextCodec.setCodecForLocale(codec)
    window = ColorPanel()
    window.setWindowTitle("颜色面板控件集合")
    window.show()
    sys.exit(app.exec_())
コード例 #4
0
 def testCodecsNames(self):
     for codec_name in QTextCodec.availableCodecs():
         codec = QTextCodec.codecForName(codec_name)
         self.assertTrue(type(codec), QTextCodec)
コード例 #5
0
 def testCodecsNames(self):
     for codec_name in QTextCodec.availableCodecs():
         codec = QTextCodec.codecForName(codec_name)
         self.assert_(type(codec), QTextCodec)
コード例 #6
0
ファイル: qtextstream_test.py プロジェクト: zhoub/pyside2
    def testCodec(self):
        '''QTextStream set/get Codec'''

        codec = QTextCodec.codecForName('ISO8859-1')
        self.obj.setCodec(codec)
        self.assertEqual(codec, self.obj.codec())