Unsolved Qt Designer i PyQt5 - jak przekazywać dane między oknami!
-
Witam!
Zaprojektowałem dwa okienka okno1 i okno2 w Qt Designer.
Nie chcę konwertować ich do pliku .py , gdyż chcę dodawać jeszcze elementy.
Napisałem skrypt w pythonie (pyqt5) by otiwerać okienka.
Niestety nie wiem ak przekazywać dane między okienkami.
W moim przykładzie po wyborze z okna 1 z list widget - i wciśnięcia przyciszku add adress by wybranty elememt pokazał się w label w oknie 2 a po wprowadzeniu adresu w oknie 2 i zatwierdzeniu pokazał się w oknie 1.
window1 -okno1.ui is:
'''<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QListWidget" name="listWidget">
<property name="geometry">
<rect>
<x>70</x>
<y>80</y>
<width>131</width>
<height>311</height>
</rect>
</property>
<item>
<property name="text">
<string>Adres 1</string>
</property>
</item>
<item>
<property name="text">
<string>Adres 2</string>
</property>
</item>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>70</x>
<y>30</y>
<width>251</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>List of adress</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>70</x>
<y>420</y>
<width>85</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Add adress</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>'''Window2 okno2.ui is:
'''<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>558</width>
<height>446</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>50</x>
<y>40</y>
<width>191</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Give name of adress</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>50</x>
<y>280</y>
<width>85</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Accept</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>170</x>
<y>30</y>
<width>151</width>
<height>27</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="chosen_adress">
<property name="geometry">
<rect>
<x>190</x>
<y>100</y>
<width>211</width>
<height>131</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>'''My python script is:
Skrypt odczytuje plik Ui z designera (script open ui files)
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialogclass Window2(QDialog):
def init(self):
super().init()
uic.loadUi("/home/ewcia/PycharmProjects/Designer_ui/okno2.ui",self) #link to window 2
self.pushButton.clicked.connect(self.akcja2)pyqtSlot() def akcja2(self): new_adres= self.lineEdit.text() # How to add this new address to Mywindow
#---------------------------------------------------------------------------------------------------------
class Mywindow(QtWidgets.QMainWindow):
def init(self):
super(Mywindow,self).init()
uic.loadUi("/home/ewcia/PycharmProjects/Designer_ui/okno1.ui", self) #link to open okno 1 on my diskself.pushButton.clicked.connect(self.akcja1) pyqtSlot() def akcja1(self): #print("druga akcja Drugie Okno") self.okno2 = Window2() self.okno2.show()
if name== "main":
import sys
app=QtWidgets.QApplication(sys.argv)
window=Mywindow()
window.show()
sys.exit(app.exec_())
'''