Aug-31-2019, 07:03 AM
I stuck with programming as I can't find solution.
I design simple windows in qt designer .ui files.
File number 1 is main window okno1.ui and window number 2 is qwidget okno2.ui
Then I created script in python which open both windows. However I don't know how to make any communication between the windows. I would like to send some data from window one to window two and from window 2 to window one. I need simple example and explanation. Ideal for me would be if you could put some code to my script which get from list widget (window one) and put to choosen_addres label to window 2. And from window two from line edit to list widget in window one.
I do not want to convert ui to py as I plan to modify the ui files in the future.
window1 -okno1.ui is:
I design simple windows in qt designer .ui files.
File number 1 is main window okno1.ui and window number 2 is qwidget okno2.ui
Then I created script in python which open both windows. However I don't know how to make any communication between the windows. I would like to send some data from window one to window two and from window 2 to window one. I need simple example and explanation. Ideal for me would be if you could put some code to my script which get from list widget (window one) and put to choosen_addres label to window 2. And from window two from line edit to list widget in window one.
I do not want to convert ui to py as I plan to modify the ui files in the future.
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 QDialog class 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 disk self.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_())I would be glad for any help