How to reset an UI in PyQt5 - python

I'm building a layout in pyqt5 where you can dynamically add or delete widgets. Below you can see a simplified version of my problem: after the successful deleting of the nested layout "nested_hbox" and its widgets it won't build up again and just shows an empty window.
Edit: In my real application I have a grid layout where you can dynamically add diagrams in shape of a matrix to view multiple incoming values from an interface. For that you can quantify the number of rows and columns. So, the grid must be refreshed, when the user actuates a button.
import sys
from PyQt5.QtWidgets import *
class Window(QWidget):
def __init__(self):
super().__init__()
self.layouts = []
self.main_content_ui()
self.init_ui()
def main_content_ui(self):
"""Build up content for the main layout "vbox" """
self.lbl_hello = QLabel()
self.lbl_hello.setObjectName("lbl_hello")
self.lbl_hello.setText("Hello StackOverflow")
self.btn_reset_ui = QPushButton()
self.btn_reset_ui = QPushButton()
self.btn_reset_ui.setObjectName("btn_reset_ui")
self.btn_reset_ui.clicked.connect(self.reset_ui)
self.btn_reset_ui.setText("Reset UI")
self.nested_hbox = QHBoxLayout()
self.nested_hbox.setObjectName("nested_hbox")
self.nested_hbox.addWidget(self.lbl_hello)
self.nested_hbox.addWidget(self.btn_reset_ui)
self.layouts.append(self.layouts)
# main layout
self.vbox = QVBoxLayout()
self.vbox.setObjectName("vbox_main")
self.layouts.append(self.vbox)
self.vbox.addLayout(self.nested_hbox)
def init_ui(self):
"""Set "vbox" as main layout
"""
self.setLayout(self.vbox)
self.show()
def delete_layout(self, layout):
"""Delete all layouts from list "layouts"
"""
try:
while layout.count():
item = layout.takeAt(0)
widget = item.widget()
if widget is not None:
widget.deleteLater()
else:
self.delete_layout(item.layout())
except Exception as e:
print(e)
def reset_ui(self):
"""Clear and reinitalize main layouts content"""
for lay in self.layouts:
self.delete_layout(lay)
print("Layout deleted rebuild layout")
self.main_content_ui()
self.vbox.update()
QMainWindow.update(self)
app = QApplication(sys.argv)
ex = Window()
sys.exit(app.exec_())
I expect the same Window as before clicking the reset-button but the window doesn't show anything.

There's a nice way presented by Qt Wiki on how to make your application restartable https://wiki.qt.io
EXIT_CODE_REBOOT = -11231351
def main():
exitCode = 0
while True:
try: app = QApplication(sys.argv)
except RuntimeError: app = QApplication.instance()
window = MainUI()
window.show()
exitCode = app.exec_()
if exitCode != EXIT_CODE_REBOOT: break
return exitCode

Related

How to open and close my SubWindow In QMdiArea in PyQt5?

In QMidArea how to open a SubWindow? My Programs as follows. My intention to open/attach my second program in SubWindow. But Nothing Will happen. visible Only blank Window. How to resolve it?
How to attach my file in QMdi Sub-window ? and after my work, how to close the sub-window properly?
Main Programme
import sys,os
from PyQt5.QtWidgets import *
from sample_countrypage import Countrypage
class MainPage(QMainWindow):
def __init__(self):
super().__init__()
self.mdi = QMdiArea()
self.setWindowTitle(" Sample Programme")
self.setGeometry(100,100,1600,600)
self.Ui()
self.show()
def Ui(self):
self.btn1=QPushButton("Country")
self.btn1.setFixedSize(100, 30)
self.btn1.clicked.connect(self.countrypage)
self.left_layout = QVBoxLayout()
self.main_layout = QHBoxLayout()
self.left_layout.setContentsMargins(3,5,5,3)
self.left_layout.addWidget(self.btn1)
self.left_layout.addStretch()
self.main_layout.setSpacing(5)
self.main_layout.setContentsMargins(0,0,0,0)
self.main_layout.addLayout(self.left_layout)
self.main_layout.addStretch()
self.setLayout(self.main_layout)
widget = QWidget()
widget.setLayout(self.main_layout)
self.setCentralWidget(widget)
def countrypage(self):
print("country page")
self.countrywindow = Countrypage()
subwindow = QMdiSubWindow()
subwindow.setWidget(self.countrywindow)
self.mdi.addSubWindow(subwindow)
# subwindow.setFixedSize(500,500)
subwindow.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
mainwindow = MainPage()
app.setStyle("fusion")
mainwindow.show()
sys.exit(app.exec_())
Second Program
import sys,os
from PyQt5.QtWidgets import *
class Countrypage(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Country Page")
self.btn1 = QPushButton("Accept")
self.btn1.clicked.connect(self.result)
self.btn2 = QPushButton("Re Enter")
self.form_layout = QFormLayout()
self.form_layout.addRow("Country",QLineEdit())
self.form_layout.addRow("continent",QLineEdit())
self.layout_btn = QHBoxLayout()
self.layout_btn.addStretch()
self.layout_btn.addWidget(self.btn1)
self.layout_btn.addWidget(self.btn2)
self.layout_country = QVBoxLayout()
self.layout_country.addLayout(self.form_layout)
self.layout_country.addLayout(self.layout_btn)
self.layout_country.addStretch()
self.setLayout(self.layout_country)
def result(self):
print("bye")
exec .close()
if __name__=="__main__":
app = QApplication(sys.argv)
countrywin = Countrypage()
countrywin.show()
sys.exit(app.exec_())
First of all, there are two main issues with your code:
You never added the mdi area to the main layout (and you also tried to set the layout for the QMainWindow, which is forbidden);
exec is a python builtin, and has no close attribute; if you want to close the widget, you have to call self.close();
Then, the setWidget() method of QMdiSubWindow reparents the widget:
QMdiSubWindow takes temporary ownership of widget;
This means that if you want to close the sub window that contains the widget from that widget, you have to check the parent and eventually close it, as soon as you verify that it's an instance of QMdiSubWindow.
class Countrypage(QWidget):
# ...
def result(self):
print("bye")
# ensure that the parent is actually a subwindow
if isinstance(self.parent(), QMdiSubWindow):
self.parent().close()
else:
self.close()
Alternatively, you can use a custom signal and connect that when creating the subwindow.
class Countrypage(QWidget):
closeRequested = pyqtSignal()
# ...
def result(self):
print("bye")
self.closeRequested.emit()
class MainPage(QMainWindow):
# ...
def countrypage(self):
print("country page")
self.countrywindow = Countrypage()
subwindow = QMdiSubWindow()
subwindow.setWidget(self.countrywindow)
self.mdi.addSubWindow(subwindow)
subwindow.show()
self.countrywindow.closerequested.connect(subwindow.close)
If you want to close the active subwindow from the mdi area (or outside of it) and no matter what that sub window is, just call self.mdi.closeActiveSubWindow().
Note that if you're going to create multiple Countrypage instances, there's no point in creating an instance attribute (self.countrywindow) as it will always be overwritten as soon as another instance will be created. Adding the widget to the subwindow and that subwindow to the mdi area will automatically create a persistent reference (due to the parenting); if you need a python reference to existing pages, then create a list as an instance member in the __init__ (eg. self.pages = []) and add the new instances to that list.

The layout is incorrect after remove widget

I am implement my project using pyqt5. Currently, I have a window including many widget. Now, I want to remove some widgets. The window looks like:
Now, I want to remove the 'name1' widget including the QLabel and QPushButton.
However, after removing all 'name1' widgets, the 'name2' widgets including QLabel and QPushButton can not self-adapte with the window, like:
All my code is:
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class Window(QDialog):
def __init__(self):
super().__init__()
self.initGUI()
self.show()
def initGUI(self):
layout = QVBoxLayout()
self.setLayout(layout)
removeLayout = QHBoxLayout()
self.__removeText = QLineEdit()
self.__removeBtn = QPushButton('Remove')
self.__removeBtn.clicked.connect(self.remove)
removeLayout.addWidget(self.__removeText)
removeLayout.addWidget(self.__removeBtn)
ROIsLayout = QVBoxLayout()
for name in ['name1', 'name2']:
subLayout = QHBoxLayout()
subText = QLabel(name)
subText.setObjectName(name)
subBtn = QPushButton(name)
subBtn.setObjectName(name)
subLayout.addWidget(subText)
subLayout.addWidget(subBtn)
ROIsLayout.addLayout(subLayout)
layout.addLayout(removeLayout)
layout.addLayout(ROIsLayout)
self.__ROIsLayout = ROIsLayout
def remove(self, checked=False):
name = self.__removeText.text()
while True:
child = self.__ROIsLayout.takeAt(0)
if child == None:
break
while True:
subChild = child.takeAt(0)
if subChild == None:
break
obName = subChild.widget().objectName()
if name == obName:
widget = subChild.widget()
widget.setParent(None)
child.removeWidget(widget)
self.__ROIsLayout.removeWidget(widget)
del widget
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec_())
update:
Actually, the issue may be the takeAt. The following code is workable:
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class Window(QDialog):
def __init__(self):
super().__init__()
self.initGUI()
self.show()
def initGUI(self):
layout = QVBoxLayout()
self.setLayout(layout)
removeLayout = QHBoxLayout()
self.__removeText = QLineEdit()
self.__removeBtn = QPushButton('Remove')
self.__removeBtn.clicked.connect(self.remove)
removeLayout.addWidget(self.__removeText)
removeLayout.addWidget(self.__removeBtn)
ROIsLayout = QVBoxLayout()
for name in ['name1', 'name2']:
subLayout = QHBoxLayout()
subLayout.setObjectName(name)
subText = QLabel(name, parent=self)
subText.setObjectName(name)
subBtn = QPushButton(name, parent=self)
subBtn.setObjectName(name)
subLayout.addWidget(subText)
subLayout.addWidget(subBtn)
ROIsLayout.addLayout(subLayout)
print(name, subLayout, subText, subBtn)
layout.addLayout(removeLayout)
layout.addLayout(ROIsLayout)
self.__ROIsLayout = ROIsLayout
self.record = [subLayout, subText, subBtn]
def remove(self, checked=False):
layout = self.record[0]
txt = self.record[1]
btn = self.record[2]
layout.removeWidget(txt)
txt.setParent(None)
txt.deleteLater()
layout.removeWidget(btn)
btn.setParent(None)
btn.deleteLater()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec_())
But, I have printed the QLabel/QPushButton in the self.record, and I find it is the same with that from child.takeAt(0).widget().
The main issue in your code is that you're constantly using takeAt(). The result is that all items in the __ROIsLayout layout will be removed from it (but not deleted), which, in your case, are the sub layouts. This is clearly not a good approach: only the widgets with the corresponding object name will be actually deleted, while the others will still be "owned" by their previous parent, will still be visible at their previous position and their geometries won't be updated since they're not managed by the layout anymore.
There are multiple solutions to your question, all depending on your needs.
If you need to remove rows from a layout, I'd consider setting the object name on the layout instead, and look for it using self.findChild().
Also consider that, while Qt allows setting the same object name for more than one object, that's not suggested.
Finally, while using del is normally enough, it's usually better to call deleteLater() for all Qt objects, which ensures that Qt correctly removes all objects (and related parentship/connections).
Another possibility, for this specific case, is to use a QFormLayout.

App size doesn't change when size() is called after hiding widgets

I'm trying to resize my app to a smaller size after a widget is hidden and its sizePolicy is set to Ignored. However, the app will not resize to smaller than it was before, as if the hidden widget is still there taking up space.
I've tried including self.update(), self.updateGeometry(), and app.processEvents() after hiding the second widget/setting its sizePolicy to Ignored and before trying to resize the app, but none of them seem to have any effect.
class App(QWidget):
def __init__(self):
super().__init__()
# basic setup
self.move(100, 100)
# main widgets
self.advanced_metadata = QCheckBox("Advanced", self)
self.advanced_metadata.stateChanged.connect(self.displayAdvanced)
self.first_widget = QLabel('first_widget', self)
self.second_widget = QLabel('second_widget', self)
self.second_widget.setHidden(True)
self.second_widget.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
# main layout
self.setLayout(QVBoxLayout())
self.layout().addWidget(self.advanced_metadata)
self.layout().addWidget(self.first_widget)
self.layout().addWidget(self.second_widget)
self.layout().addStretch()
self.resizeApp(650, self.sizeHint().height())
self.show()
# toggles advanced metadata view
def displayAdvanced(self):
if self.advanced_metadata.isChecked():
self.second_widget.setVisible(True)
self.second_widget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.resizeApp(650, self.sizeHint().height())
else:
self.second_widget.setHidden(True)
self.second_widget.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
self.resizeApp(650, self.sizeHint().height())
# resizes main window
def resizeApp(self, width, height):
self.resize(width, height)
print(self.size())
if __name__ == '__main__':
# accounts for exiting errors in python
if not QApplication.instance():
app = QApplication(sys.argv)
else:
app = QApplication.instance()
ex = App()
app.exec_()
I expect the size of the window when initialized to be 650x112, then when the Advanced checkbox is selected the size should change to 650x149, and lastly, when the Advanced checkbox is unchecked, the size should revert back to 650x112. The last expectation does not occur; instead, the window remains at 650x149.
In Qt many of the tasks are done asynchronously, and that is the case of geometry, so even if you have changed the policies this will not apply immediately until the synchronous part ends. So a workaround is to use QTimer.singleShot(0, ...) to apply the resizing one instant later.
from functools import partial
from PyQt5 import QtCore, QtWidgets
class App(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.move(100, 100)
# main widgets
self.advanced_metadata = QtWidgets.QCheckBox(
"Advanced", stateChanged=self.displayAdvanced
)
self.first_widget = QtWidgets.QLabel("first_widget")
self.second_widget = QtWidgets.QLabel("second_widget")
self.second_widget.setHidden(True)
self.second_widget.setSizePolicy(
QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored
)
lay = QtWidgets.QVBoxLayout(self)
lay.addWidget(self.advanced_metadata)
lay.addWidget(self.first_widget)
lay.addWidget(self.second_widget)
lay.addStretch()
self.resizeApp(650, self.sizeHint().height())
# toggles advanced metadata view
#QtCore.pyqtSlot(int)
def displayAdvanced(self, state):
if state == QtCore.Qt.Checked:
self.second_widget.show()
self.second_widget.setSizePolicy(
QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Preferred,
)
else:
self.second_widget.hide()
self.second_widget.setSizePolicy(
QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored
)
wrapper = partial(self.resizeApp, 650, self.sizeHint().height())
QtCore.QTimer.singleShot(0, wrapper)
#QtCore.pyqtSlot(int, int)
def resizeApp(self, width, height):
self.resize(width, height)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication.instance()
if app is None:
app = QtWidgets.QApplication(sys.argv)
ex = App()
ex.show()
sys.exit(app.exec_())

Pyqt4 Qcombobox signal is not firing upon user input but it does when done with .setCurrentIndex

The QComboBox currentIndexChanged Signal is not firing when a new item is selected from user. But it does fire when .setCurrentIndex is used within the code. (line 91 and 92).
I have a QTabWidget. In tab1 I have a Qvbox into which three Qhboxes are added. Each Qhbox is from the class Kaskade and contains two widgets, a QCombobox and a QstackedWidget. Depending of the current Index of the QCombobox the QstackWidget will either show a QLCD number or a Qspinbox.
If the user changes the QCombobox index in the GUI the currentIndexChanged Signal is not emitted, although the QCombobox shows the new item.
What am I missing? Any kind of help is appreciated.
This is my test code
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import sys
class Kaskade(QtGui.QWidget):
def __init__(self,sp,sp_min,sp_max, parent = None):
super(Kaskade, self).__init__(parent)
self._sp=sp
self._sp_min=sp_min
self._sp_max=sp_max
self.sp()
self.hbox_gen()
def mode_changed(self,i):
print "Mode has changed to", i
self.sp_stack.setCurrentIndex(i)
def sp(self):
self.sp_stack=QtGui.QStackedWidget(self)
self.sp1 = QtGui.QWidget()
self.sp2 = QtGui.QWidget()
self.sp1UI()
self.sp2UI()
self.sp_stack.addWidget(self.sp1)
self.sp_stack.addWidget(self.sp2)
def sp1UI(self):
self.sp1_layout=QtGui.QHBoxLayout()
self.sp1_lcd=QtGui.QLCDNumber(self)
self.sp1_layout.addWidget(self.sp1_lcd)
#self.sp1.connect(lcd_pv.display)
self.sp1.setLayout(self.sp1_layout)
def sp2UI(self):
self.sp2_layout=QtGui.QHBoxLayout()
self.sp2_spinBox=QtGui.QSpinBox()
self.sp2_spinBox.setRange(self._sp_min,self._sp_max)
self.sp2_spinBox.setValue(self._sp)
self.sp2_layout.addWidget(self.sp2_spinBox)
self.sp2.setLayout(self.sp2_layout)
def hbox_gen(self):
self.mode=QtGui.QComboBox(self)
self.mode.addItem("OFF")
self.mode.addItem("ON")
self.mode.currentIndexChanged.connect(self.mode_changed)
self.hbox = QtGui.QHBoxLayout()
self.hbox.addWidget(self.mode)
self.hbox.addWidget(self.sp_stack)
class tabdemo(QtGui.QTabWidget):
def __init__(self, parent = None):
super(tabdemo, self).__init__(parent)
self.tab1 = QtGui.QWidget()
self.tab2 = QtGui.QWidget()
self.tab3 = QtGui.QWidget()
self.addTab(self.tab1,"Tab 1")
self.addTab(self.tab2,"Tab 2")
self.addTab(self.tab3,"Tab 3")
self.tab1UI()
self.tab2UI()
self.tab3UI()
self.setWindowTitle("Heizung")
def tab1UI(self):
K1=Kaskade(28,5,40)
K2=Kaskade(30,5,40)
K3=Kaskade(35,5,40)
K1.mode.setCurrentIndex(1)
K3.mode.setCurrentIndex(1)
vbox = QtGui.QVBoxLayout()
vbox.addLayout(K1.hbox)
vbox.addLayout(K2.hbox)
vbox.addLayout(K3.hbox)
self.tab1.setLayout(vbox)
self.setTabText(1,"Tab1")
def tab2UI(self):
self.setTabText(1,"Tab2")
def tab3UI(self):
self.setTabText(2,"Tab3")
def main():
app = QtGui.QApplication(sys.argv)
ex = tabdemo()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
You must add Kaskade to vbox in Tab 1, not the layout. In addition we must do self.hbox layout of Kaskade:
class Kaskade(QtGui.QWidget):
[...]
def hbox_gen(self):
[...]
self.hbox = QtGui.QHBoxLayout(self)
[...]
class tabdemo(QtGui.QTabWidget):
[...]
def tab1UI(self):
[...]
vbox = QtGui.QVBoxLayout()
vbox.addWidget(K1)
vbox.addWidget(K2)
vbox.addWidget(K3)
self.tab1.setLayout(vbox)
[...]

PyQt Make parent GUI wait till child GUI is closed

I am new to pyqt.I am trying to invoke a child GUI when a button is clicked in the parent GUI. In this process, parent GUI has to wait for the child GUI to be closed by the user after selecting some inputs. But this is not happening, Parent GUI does execute the next lines after which the child GUI has been invoked. Below is the code where I am passing an argument to child GUI from parent GUI. The child GUI will return value based on OK/Cancel button click
Code:
import sys
from PyQt4 import QtGui,QtCore,Qt
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Child(QtGui.QWidget):
def __init__(self,switches=None):
super(Child,self).__init__()
self.swwidget = QtGui.QWidget()
self.swlayout = QtGui.QGridLayout()
switches = ['abc1','def1']
switches.sort()
self.switches = switches
def switchesUI(self):
self.swwidget.setWindowModality(QtCore.Qt.ApplicationModal)
self.swl = len(self.switches)
self.sw = {}
self.addsw = []
print ("I am in switchesUI")
#Add the switches to layout dynamically
for i in range(self.swl):
self.sw[i] = QtGui.QCheckBox(self.switches[i])
self.swlayout.addWidget(self.sw[i],i,0)
self.swbuttonbox = QtGui.QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel);
self.swbuttonbox.setOrientation(QtCore.Qt.Horizontal)
self.swlayout.addWidget(self.swbuttonbox)
self.swwidget.setWindowTitle('Switches')
self.swwidget.setLayout(self.swlayout)
self.swwidget.show()
self.connect(self.swbuttonbox,QtCore.SIGNAL("accepted()"),self.swaccept)
self.connect(self.swbuttonbox,QtCore.SIGNAL("rejected()"),self.swreject)
def swaccept(self):
for i in range(self.swl):
if self.sw[i].isChecked():
self.addsw.append(self.switches[i])
self.swwidget.close()
return self.addsw
def swreject(self):
self.swwidget.close()
return None
class Parent(QtGui.QWidget):
def __init__(self):
super(Parent,self).__init__()
QtGui.QWidget.__init__(self)
self.button = QtGui.QPushButton('Test', self)
self.layout = QtGui.QVBoxLayout(self)
self.layout.addWidget(self.button)
self.assw = ['Test1','Test2']
self.CH = Child(self.assw)
self.connect(self.button,SIGNAL("clicked()"),self.popup)
print ("Child GUI closed")
def popup(self):
self.CH.switchesUI()
def main():
app = QtGui.QApplication(sys.argv)
form = Parent()
form.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
After the button "Test" is clicked, a child GUI will pop-up. I don't want the statement "Child GUI Closed" to be printed till the child GUI is closed.
Can someone suggest me how to achieve this functionality ?
You have to handle closeEvent to perform operations when a window wants to close, also since your Child class inherits from QWidget which means it's a QWidget itself you dont need to create another one with self.swwidget
import sys
from PyQt4 import QtGui,QtCore,Qt
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Child(QtGui.QWidget):
def __init__(self,switches=None):
super(Child,self).__init__()
# self.swwidget = QtGui.QWidget() # you don't need to do this you can add all the properties to self
self.swlayout = QtGui.QGridLayout()
switches = ['abc1','def1']
switches.sort()
self.switches = switches
def switchesUI(self):
self.setWindowModality(QtCore.Qt.ApplicationModal)
self.swl = len(self.switches)
self.sw = {}
self.addsw = []
print ("I am in switchesUI")
#Add the switches to layout dynamically
for i in range(self.swl):
self.sw[i] = QtGui.QCheckBox(self.switches[i])
self.swlayout.addWidget(self.sw[i],i,0)
self.swbuttonbox = QtGui.QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel);
self.swbuttonbox.setOrientation(QtCore.Qt.Horizontal)
self.swlayout.addWidget(self.swbuttonbox)
self.setWindowTitle('Switches')
self.setLayout(self.swlayout)
self.show()
self.connect(self.swbuttonbox,QtCore.SIGNAL("accepted()"),self.swaccept)
self.connect(self.swbuttonbox,QtCore.SIGNAL("rejected()"),self.swreject)
def swaccept(self):
for i in range(self.swl):
if self.sw[i].isChecked():
self.addsw.append(self.switches[i])
self.close()
return self.addsw
def swreject(self):
self.close()
return None
def closeEvent(self, event):
print ("Child GUI closed")
class Parent(QtGui.QWidget):
def __init__(self):
super(Parent,self).__init__()
QtGui.QWidget.__init__(self)
self.button = QtGui.QPushButton('Test', self)
self.layout = QtGui.QVBoxLayout(self)
self.layout.addWidget(self.button)
self.assw = ['Test1','Test2']
self.CH = Child(self.assw)
self.connect(self.button,SIGNAL("clicked()"),self.popup)
def popup(self):
self.CH.switchesUI()
def main():
app = QtGui.QApplication(sys.argv)
form = Parent()
form.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

Categories