Python Forum
[PyQt] Send data between windows Pyqt5 and Qt Designer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Send data between windows Pyqt5 and Qt Designer
#1
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:
<?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
Reply


Messages In This Thread
Send data between windows Pyqt5 and Qt Designer - by kkonrad002 - Aug-31-2019, 07:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PyQt5 form not displaying my data from SQLite3 Database Linuxdesire 2 4,987 Jan-10-2023, 09:51 PM
Last Post: gradlon93
  QT Designer Krissstian 4 1,716 May-26-2022, 09:45 AM
Last Post: Krissstian
  Qt Designer : help document viewer error. davediamond 2 1,596 Apr-14-2022, 10:38 AM
Last Post: davediamond
  GUI programming PyQt 5 + Qt Designer flash77 9 2,742 Mar-19-2022, 10:31 AM
Last Post: flash77
  [PyQt] QT5 Designer Drawing greenhorn1 1 2,569 Dec-30-2021, 05:12 PM
Last Post: deanhystad
  Installed Designer - Helpf Files for "assistant" are missing Valmont 0 2,006 Mar-22-2021, 11:09 AM
Last Post: Valmont
  Using a GUI Designer vs. hard coding 357mag 9 6,087 Feb-21-2021, 06:43 PM
Last Post: kkaur
  Attempting to use Qt Designer. thewolf 17 6,139 Feb-17-2021, 12:03 AM
Last Post: thewolf
  [PyGUI] help code python QT Designer yan_mhb 0 1,924 Aug-12-2020, 09:32 AM
Last Post: yan_mhb
  [PyQt] Pyqt5: How do you make a button that adds new row with data to a Qtablewidget YoshikageKira 6 7,025 Jan-02-2020, 04:32 PM
Last Post: Denni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020