鱼C论坛

 找回密码
 立即注册
查看: 3078|回复: 2

PyQt5两个窗体之间信息传递问题

[复制链接]
发表于 2017-3-23 00:31:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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,它告诉没有这个属性,我搞不懂了
有谁会的,或者会信号量与槽的,求帮助
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-4-10 17:37:29 | 显示全部楼层
我也有这样的问题,楼主解决了吗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-4-10 21:48:06 | 显示全部楼层
https://fishc.com.cn/thread-131082-1-1.html  我用pyqt写的,用到信号和槽,不知道能不能帮到你,我自己不是很熟悉,参照视频写的,有需要可以下载代码自己看下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-2-11 21:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表