Hello Everybody!
First of all thanks for all the input I received here. In the sequence is the source code working -- or at least working 80% perfectly well.
As you can see in the sequence, the function addBox is called, but it doesn't add the groupBox for the second time it runs.
Here are the imports:
#//===========================================================//#
import os
import platform
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
#//===========================================================//#
Here is the Ui_Addwidget class..
#//===========================================================//#
class Ui_Addwidget(object):
def runbutton3(self):
print "hello // radioButton3.isChecked : ", self.radioButton3.isChecked()
def runButton4(self):
print "nice // radioButton4.isChecked : ", self.radioButton4.isChecked()
def addBox(self):
self.vLayout_wdg = QtGui.QWidget(self.centralwidget)
self.vLayout_wdg.setGeometry(QtCore.QRect(40, 160, 171, 121))
self.vLayout_wdg.setObjectName("vLayout_wdg")
self.vLayoutBoxObj = QtGui.QHBoxLayout()
self.vLayout_wdg.setLayout(self.vLayoutBoxObj)
self.newGroupBox = self.vLayout_wdg.newGroupBox = QtGui.QGroupBox(self.vLayout_wdg)
self.newGroupBox.setObjectName("newGroupBox")
self.newGroupBox.setTitle(QtGui.QApplication.translate("MainWindow", "newGroupBox", None, QtGui.QApplication.UnicodeUTF8))
self.groupLayoutBox = QtGui.QVBoxLayout()
self.groupLayoutBox.setObjectName("groupLayoutBox")
self.newGroupBox.setLayout(self.groupLayoutBox)
self.radioButton3 = QtGui.QRadioButton()
self.radioButton3.setGeometry(QtCore.QRect(30, 30, 101, 21))
self.radioButton3.setObjectName("helloRadioButton")
self.radioButton3.setText(QtGui.QApplication.translate("MainWindow", "say: Hello", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton4 = QtGui.QRadioButton()
self.radioButton4.setGeometry(QtCore.QRect(30, 60, 111, 18))
self.radioButton4.setObjectName("niceRadioButton")
self.radioButton4.setText(QtGui.QApplication.translate("MainWindow", "say: Nice", None, QtGui.QApplication.UnicodeUTF8))
self.groupLayoutBox.addWidget(self.radioButton3)
self.groupLayoutBox.addWidget(self.radioButton4)
self.vLayoutBoxObj.insertWidget(0, self.newGroupBox)
def on_show(self):
print "addBox // radioButton1.isChecked : ", self.radioButton1.isChecked()
if not self.vLayout_wdg.newGroupBox:
self.addBox()
def on_hide(self):
print "deleteBox // radioButton2.isChecked : ", self.radioButton2.isChecked()
if self.vLayout_wdg.newGroupBox:
self.vLayout_wdg.newGroupBox.deleteLater()
self.vLayout_wdg.newGroupBox = None
def connectEvent(self):
QtCore.QObject.connect(self.radioButton1, QtCore.SIGNAL("toggled(bool)"),self.on_show)
QtCore.QObject.connect(self.radioButton2, QtCore.SIGNAL("toggled(bool)"),self.on_hide)
QtCore.QObject.connect(self.radioButton3, QtCore.SIGNAL("toggled(bool)"),self.runbutton3)
QtCore.QObject.connect(self.radioButton4, QtCore.SIGNAL("toggled(bool)"),self.runButton4)
def selectBox(self):
self.selectGroupBox = QtGui.QGroupBox(self.centralwidget)
self.selectGroupBox.setGeometry(QtCore.QRect(40, 20, 171, 111))
self.selectGroupBox.setObjectName("selectGroupBox")
self.selectGroupBox.setTitle(QtGui.QApplication.translate("MainWindow", "select", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton1 = QtGui.QRadioButton(self.selectGroupBox)
self.radioButton1.setGeometry(QtCore.QRect(30, 30, 111, 18))
self.radioButton1.setObjectName("radioButton1")
self.radioButton1.setText(QtGui.QApplication.translate("MainWindow", "add groupbox", None, QtGui.QApplication.UnicodeUTF8))
self.radioButton2 = QtGui.QRadioButton(self.selectGroupBox)
self.radioButton2.setGeometry(QtCore.QRect(30, 60, 111, 18))
self.radioButton2.setObjectName("radioButton2")
self.radioButton2.setText(QtGui.QApplication.translate("MainWindow", "delete groupbox", None, QtGui.QApplication.UnicodeUTF8))
def addwidget_centralwdg(self,MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.selectBox()
self.addBox()
self.connectEvent()
MainWindow.setCentralWidget(self.centralwidget)
def addwidget_setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(250, 300)
self.addwidget_centralwdg(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
#//===========================================================//#
Here you have the mainDesign class...
#//===========================================================//#
class mainDesign(QtGui.QMainWindow,Ui_Addwidget):
def __init__(self,parent=None):
super(mainDesign,self).__init__(parent)
self.addwidget_setupUi(self)
#//===========================================================//#
And of course, the def main...
#//===========================================================//#
def main():
app = QtGui.QApplication(sys.argv)
main = mainDesign()
main.show()
sys.exit(app.exec_())
main()
#//===========================================================//#
To try it, just copy the code and the classes to a *.py file. And it will run.
Any other comments or suggestions to solve the missing piece of the puzzle, are highly welcome and appreciated.