将函数应用于QtextEdit或QPlainTextEdit python pyside2

将函数应用于QtextEdit或QPlainTextEdit python pyside2,python,pyside2,Python,Pyside2,我想问您如何在QTextEdit或QPlainTextEdit中打印结果, 我在这里和其他一些网站上尝试了一些组合,但没有任何效果, 如果有人能帮我修一下,我会很高兴的 这是我的代码: from PySide2 import QtCore, QtWidgets from PySide2.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit,QPlainTextEdit, QTextEdit, QMessageBox, QApplicat

我想问您如何在QTextEdit或QPlainTextEdit中打印结果, 我在这里和其他一些网站上尝试了一些组合,但没有任何效果, 如果有人能帮我修一下,我会很高兴的

这是我的代码:

from PySide2 import QtCore, QtWidgets
from PySide2.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit,QPlainTextEdit, QTextEdit, QMessageBox, QApplication
from PySide2.QtWidgets import QPushButton
from PySide2.QtCore import QSize
#from PySide2.QtGui import *
import sys

class Cam_Ext(QMainWindow):


    def __init__(self, Custom):
        QMainWindow.__init__(self, Custom)

        self.setMinimumSize(QSize(700, 900))
        self.setWindowTitle("Print groupes seletionner")

        ###btn1
        self.btn = QtWidgets.QPushButton('Print groupes' , self)
        self.btn.move(180, 100)
        self.btn.resize(350, 40)
        self.btn.setStyleSheet("background-color: rgb(255, 255, 255); font-family: arial; font-size: 17px; font-weight: bold;")
        self.btn.clicked.connect(self.Renommer)

        self.line = QPlainTextEdit(self)
        self.line.setStyleSheet("font-size: 12px; font-weight: bold; ")
        self.line.move(100, 170)
        self.line.resize(500, 400)
        self.line.setText(self.Renommer)
        #self.line.setPlaceholderText(self.Renommer)


        self.show()
    def Renommer(self):
        # -*- coding: utf-8 -*-
        import PhotoScan
        import os
        doc = PhotoScan.app.document
        pr_name = doc.path
        project_name = os.path.split(pr_name)[-1]
        print(project_name)

        groups = doc.chunk.camera_groups
        # print(groups)
        #x = 0
        seg = "SEG01"
        for group in groups:
            # print(group)
            if group.selected:
                print(project_name, "-",group, "-", seg, ";")
                #x += 1
def main():

    global doc
    doc = PhotoScan.app.document

    global app
    app = QtWidgets.QApplication.instance()
    Custom = app.activeWindow()

    dlg = Cam_Ext(Custom)

PhotoScan.app.addMenuItem("Pp/Print groupes seletionner", main)
我必须用兰姆达?我不知道如何打印函数的结果 在我的文本窗口内,在附加模式下,每次单击我的QPushButton时,我都希望保留我的文本并在下面添加新内容,在此窗口中,请帮助我,我需要更改什么

这是我的指纹,如果有帮助的话:

    2018-08-09 14:29:54 Error: 'PySide2.QtWidgets.QTextEdit.insertPlainText' called with wrong argument types:
2018-08-09 14:29:54   PySide2.QtWidgets.QTextEdit.insertPlainText(PySide2.QtWidgets.QHBoxLayout)
2018-08-09 14:29:54 Supported signatures:
2018-08-09 14:29:54   PySide2.QtWidgets.QTextEdit.insertPlainText(unicode)

必须使用
appendPlainText()
将文本添加到循环中


您指出的错误与您的代码不符,因为您没有使用insertPlainText。我已经尝试过insertPlainText,但doe没有工作:(您知道我如何增加seg=“SEG01”吗,当我按下按钮时,他会在我的文本编辑器中打印文本,当我再次按下时,我想增加一个seg,就像第一次是…-SEG01;,第二次是…-SEG02;,第三次是…-SEG03;…等等?我添加了新问题[如果你想检查它:-)
class Cam_Ext(QMainWindow):
    def __init__(self, Custom):
        QMainWindow.__init__(self, Custom)
        ...
        self.btn.clicked.connect(self.Renommer)

        self.line = QPlainTextEdit(self)
        self.line.setStyleSheet("font-size: 12px; font-weight: bold; ")
        self.line.move(100, 170)
        self.line.resize(500, 400)
        self.show()

    def Renommer(self):
        ...
        # uncomment if you want to clean the previous text
        # self.line.clear()
        for group in groups:
            # print(group)
            if group.selected:
                self.line.appendPlainText("{}-{}-{};".format(project_name, group, seg))