马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialog
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Mainwindow(object):
def setupUi(self, Mainwindow):
Mainwindow.setObjectName("Mainwindow")
Mainwindow.resize(400, 300)
Mainwindow.setSizeGripEnabled(True)
self.textBrowser = QtWidgets.QTextBrowser(Mainwindow)
self.textBrowser.setGeometry(QtCore.QRect(60, 70, 256, 51))
self.textBrowser.setObjectName("textBrowser")
self.label = QtWidgets.QLabel(Mainwindow)
self.label.setGeometry(QtCore.QRect(60, 40, 251, 16))
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(Mainwindow)
self.pushButton.setGeometry(QtCore.QRect(140, 170, 93, 28))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Mainwindow)
QtCore.QMetaObject.connectSlotsByName(Mainwindow)
def retranslateUi(self, Mainwindow):
_translate = QtCore.QCoreApplication.translate
Mainwindow.setWindowTitle(_translate("Mainwindow", "主窗体"))
self.label.setText(_translate("Mainwindow", "TextLabel"))
self.pushButton.setText(_translate("Mainwindow", "打开对话框"))
class Ui_Secondwin(object):
def setupUi(self, Secondwin):
Secondwin.setObjectName("Secondwin")
Secondwin.resize(400, 300)
Secondwin.setSizeGripEnabled(True)
self.lineEdit = QtWidgets.QLineEdit(Secondwin)
self.lineEdit.setGeometry(QtCore.QRect(100, 90, 151, 21))
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QtWidgets.QPushButton(Secondwin)
self.pushButton.setGeometry(QtCore.QRect(130, 160, 93, 28))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Secondwin)
self.pushButton.clicked.connect(Secondwin.close)
QtCore.QMetaObject.connectSlotsByName(Secondwin)
def retranslateUi(self, Secondwin):
_translate = QtCore.QCoreApplication.translate
Secondwin.setWindowTitle(_translate("Secondwin", "副窗体"))
self.pushButton.setText(_translate("Secondwin", "确定"))
class Secondwin(QDialog, Ui_Secondwin):
"""
Class documentation goes here.
"""
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent widget
@type QWidget
"""
super(Secondwin, self).__init__(parent)
self.setupUi(self)
@pyqtSlot()
def on_pushButton_clicked(self):
"""
Slot documentation goes here.
"""
my_str=self.lineEdit.text()
##########################################问题就在这
#我想通过调用函数让副窗口的字符串传给主窗口的textBrowser,但是不知道怎么写,我写了一个,错了,静态方法没法用self
# Mainwindow.chuandi(my_str, self)
Mainwindow.textBrowser.append(my_str)
self.close()
class Mainwindow(QDialog, Ui_Mainwindow):
"""
Class documentation goes here.
"""
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent widget
@type QWidget
"""
super(Mainwindow, self).__init__(parent)
self.setupUi(self)
def chuandi(str, self):
self.textBrowser.append(str)
@pyqtSlot()
def on_pushButton_clicked(self):
"""
Slot documentation goes here.
"""
secondwin = Secondwin()
secondwin.exec_()
if __name__ == "__main__":
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
dlg = Mainwindow()
dlg.show()
sys.exit(app.exec_())
我想通过调用函数让副窗口的字符串传给主窗口的textBrowser,但是不知道怎么写,我写了一个,错了.
我使用Mainmin.textBrowser,它告诉没有这个属性,我搞不懂了
有谁会的,或者会信号量与槽的,求帮助 |