PyQt widget reload or refresh
<p>My problem is that when I choose a name on widget "Form1" this name is written to file. When I click on OK button on widget "Form1" I can't see the same name on widget "Form2" which I chose previously.</p>

<p>The problem is that the widget "Form2" is not up to date. I tried to insert self.update at the beginning on the widget "Form2" but it doesn't work. How can I refresh widget "Form2" or reload the content of the file? </p>

<p>I have a simple code: </p>

<pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys

from functools import partial
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4 import QtGui, QtCore
from math import sqrt
from time import gmtime, strftime

class Form1(QWidget):
    showForm2Signal = pyqtSignal()

    def __init__(self, parent=None):
        super(Form1, self).__init__(parent)

        self.label = QtGui.QLabel(self)
        self.label.setGeometry(0, 40, 480, 400)
        self.label.move(0,40)

        #Select name
        self.styleTerminalSettings = QtGui.QLabel("Please select your name:", self)
        self.styleTerminalSettings.move(20,40)
        self.styleTerminalSettings.resize(250,30)
        self.styleTerminalSettings.setStyleSheet("color: black;  background-color: transparent; font-size: 12pt; font-weight: bold;")

        self.comboBox = QtGui.QComboBox(self)
        self.comboBox.addItem("NAME 1")
        self.comboBox.addItem("NAME 2")
        self.comboBox.addItem("NAME 3")
        self.comboBox.addItem("NAME 4")
        self.comboBox.move(20,80)
        self.comboBox.resize(440,50)
        self.comboBox.currentIndexChanged.connect(self.selectionchange)

        #OK button
        self.ok_button = QtGui.QPushButton("OK", self)
        self.ok_button.resize(self.ok_button.minimumSizeHint())
        self.ok_button.move(0,340)
        self.ok_button.resize(480,60)
        self.ok_button.setStyleSheet("color: #25373D; background-color: #71BA51;  font-size: 16pt; font-weight: bold;")

        layout = QVBoxLayout(self)

        self.ok_button.clicked.connect(self.showForm2Signal.emit)

    def selectionchange(self,i): 
        pos_user_name = self.comboBox.currentText()
        self.users_write(pos_user_name)

    #Name write to file 
    def users_write(self, pos_user_name):
        filename = "user_name_session"

        target = open(filename, 'w')
        target.truncate()
        target.write(pos_user_name)
        target.close()    

class Form2(QWidget):
    def __init__(self, parent=None):
        super(Form2, self).__init__(parent)

        global pos_user_name 

        self.label = QtGui.QLabel(self)
        self.label.setGeometry(0, 40, 480, 400)
        self.label.move(0,40)

        #Name read from file
        filename = "user_name_session"
        target = open(filename, "r+")
        name = target.read(10);

        self.styleCashRegister = QtGui.QLabel("Name:", self)
        self.styleCashRegister.move(20,40)
        self.styleCashRegister.resize(170,30)
        self.styleCashRegister.setStyleSheet("color: black; background-color: transparent;  font-size: 16pt; font-weight: bold;")

        self.cashregisterid = QtGui.QLineEdit(self)
        self.cashregisterid.setText(str(name))
        self.cashregisterid.move(100, 40)
        self.cashregisterid.resize(260,30)
        self.cashregisterid.setStyleSheet("color: #25373D;  font-size: 16pt; font-weight: bold;")

class MainWidget(QWidget):
    def __init__(self, parent=None):
        super(MainWidget, self).__init__(parent)
        self.stack = QStackedWidget()
        layout = QVBoxLayout(self)
        layout.addWidget(self.stack)
        layout.setContentsMargins(0, 0, 0, 0)

        self.setGeometry(0, 0, 480, 400)
        self.setWindowTitle("PYQT WIDGET TEST")
        self.setStyleSheet("background-color: #E8E8E8")

        self.form1 = Form1(self)
        self.form2 = Form2(self)

        self.stack.addWidget(self.form1)
        self.stack.addWidget(self.form2)

        self.form1.showForm2Signal.connect(partial(self.stack.setCurrentWidget,self.form2))

        self.stack.setCurrentWidget(self.form1) 

if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MainWidget()
    w.show()
    app.exec_()
    sys.exit()
</code></pre>