I am using python and pyqt6.
I have a maindwindow A, it has a mdi area with a subwindow havig a qlineedt and a button, when i press the button a pop up window appears which is another class from within the same program, the popup window has qlineedit and a button, when i enter a value in the qlineedit and press the button, the popup window closes and the value of the qlineedit is transferred to the qlineedit of the subwindow, I tried this code:
A.subwindow.settext(self.textedit.text())
but it does not work. The error is "qmainwindow A has no attribute subwindow" I also tried this:
A.mdi.subwindow.settext(self.textedit.text())
And the error is "qmainwindow A has no attribute mdi" I declared mdi as:
self.mdi = QMdiArea()
windowLayout.addWidget(self.mdi)
And subwindow as :
self.subwindow = QMdiSubWindow()
self.mdi.addSubWindow(self.subwindow)
self.subwindow.show()
Here's the minimal code that produces the same error:
import PyQt6.QtWidgets as qtw
import PyQt6.QtCore as qtc
import sys
import os
class Minwindow(qtw.QMainWindow):
def __init__(self):
super().__init__()
self.mdi = qtw.QMdiArea()
widget = qtw.QWidget()
self.setCentralWidget(widget)
windowLayout = qtw.QHBoxLayout(widget)
windowLayout.addWidget(self.mdi, )
pbSub = qtw.QPushButton('Sub', self)
pbSub.setGeometry(9, 9, 75, 20)
pbSub.clicked.connect(self.on_click_sub)
self.setGeometry(125,75,350,300)
def on_click_sub(self):
self.subw = qtw.QMdiSubWindow()
self.subw.txtusr = qtw.QLineEdit('', self.subw)
self.subw.txtusr.setGeometry(25,30,100,25)
pbPop = qtw.QPushButton('Pop', self.subw)
pbPop.setGeometry(50, 75, 75, 20)
pbPop.clicked.connect(self.on_click_pop)
self.subw.setGeometry(75, 75, 200, 150)
self.subw.setWindowTitle("Create User")
self.mdi.addSubWindow(self.subw)
self.subw.show()
def on_click_pop(self):
self.showPopup()
def showPopup(self):
name = 'POPS'
self.dpop = Popw(name)
self.dpop.move(self.pos().x()+75, self.pos().y()+75)
self.dpop.setFixedSize(200, 150)
self.dpop.show()
class Popw(qtw.QMainWindow):
def __init__(self, name):
super().__init__()
self.name = name
#self.setGeometry(100, 100, 300, 350)
self.setWindowFlags(qtc.Qt.WindowType.Window | qtc.Qt.WindowType.CustomizeWindowHint | qtc.Qt.WindowType.WindowStaysOnTopHint)
self.initUI()
def initUI(self):
ntxtusr = qtw.QLineEdit('', self)
ntxtusr.setGeometry(25,30,100,25)
pbOk = qtw.QPushButton('Ok', self)
pbOk.setGeometry(50, 75, 75, 20)
pbOk.clicked.connect(self.on_click_ok)
def on_click_ok(self):
Minwindow.mdi.subw.txtusr.setText(ntxtusr.text())
self.close()
if __name__ == "__main__":
app = qtw.QApplication(sys.argv)
mainl = Minwindow()
mainl.show()
sys.exit(app.exec())