from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLineEdit
from PySide6.QtCore import Signal
class MyWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("主窗口")
self.lineEditShow = QLineEdit()
self.mainLayout = QVBoxLayout()
self.mainLayout.addWidget(self.lineEditShow)
self.setLayout(self.mainLayout)
self.bind()
def bind(self):
self.subWindow = SubWindow(self)
self.subWindow.show()
class SubWindow(QWidget):
sendValueToMain = Signal(str)
def __init__(self, parent):
super().__init__()
self.setWindowTitle("子窗口")
self.parent = parent
self.move(20, 20)
self.lineEdit = QLineEdit()
self.btn = QPushButton("发送数据到主窗口")
self.mainLayout = QVBoxLayout()
self.mainLayout.addWidget(self.lineEdit)
self.mainLayout.addWidget(self.btn)
self.setLayout(self.mainLayout)
self.bind()
def bind(self):
self.sendValueToMain.connect(self.parent.lineEditShow.setText)
self.btn.clicked.connect(self.sendValue)
def sendValue(self):
value = self.lineEdit.text()
self.sendValueToMain.emit(value)
if __name__ == "__main__":
app = QApplication([])
window = MyWindow()
window.show()
app.exec()
02-21
1512
07-18
07-18
05-20
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交