[英]Apply function to QtextEdit or QPlainTextEdit python pyside2
我想問你如何在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)
我必須使用lambda嗎? 我不知道如何在我的文本窗口中以函數append的方式從函數中打印結果,我想將我的文本保留在其中,並在每次單擊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()
在循環中添加文本。
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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.