python - 将函数应用于 QtextEdit 或 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))
推荐阅读
- python - 如何在 python 中添加两列并更新 CSV?
- unity3d - ScrollRect 上的掩码不会隐藏滑块之外的子网格对象(但适用于文本)
- asp.net-core - 如何在评估 Razor 标签的 Razor 页面中使用内联条件
- css - Internet Explorer 10 中的导航和滑块会发生什么情况?
- bison - 为什么 Bison 总是给我“第 x 行附近的语法错误”?
- css - 如何开始选择元素与表单中的标签对齐
- sql - 首次下订单时获取日期和唯一客户数
- python-3.x - 将元素插入二维列表
- python-3.x - Python while循环不等待用户输入
- node.js - 如何使用 Mongoose 在 NodeJS 中进行密码验证