I tried this by this way: (I'm using PyQt4)
- I generated a MainWindow using Qt Design with a widget object where I want to load another widget
- I generated a Widget using Qt Design with a simple button
Like this:
#class widget that I want to be loaded
class a(object):
def setupUi(self, Form):
Form.setObjectName("Form")
self.
btModificar = QtGui.
QPushButton(self.
centralwidget) self.
btModificar.
setGeometry(QtCore.
QRect(280,
40,
91,
21)) self.toolBox.setCurrentIndex(0)
class a(object):
def setupUi(self, Form):
Form.setObjectName("Form")
self.btModificar = QtGui.QPushButton(self.centralwidget)
self.btModificar.setGeometry(QtCore.QRect(280, 40, 91, 21))
self.toolBox.setCurrentIndex(0)
To copy to clipboard, switch view to plain text mode
#class that I want to load the widget
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
self.
centralwidget = QtGui.
QWidget(MainWindow
) self.centralwidget.setObjectName("centralwidget")
self.
btAdicionar = QtGui.
QPushButton(self.
centralwidget) self.
btAdicionar.
setGeometry(QtCore.
QRect(90,
40,
91,
21)) self.btAdicionar.setObjectName("btAdicionar")
self.
widget = QtGui.
QWidget(self.
centralwidget) self.
widget.
setGeometry(QtCore.
QRect(160,
105,
811,
471)) self.widget.setObjectName("widget")
MainWindow.setCentralWidget(self.centralwidget)
QtCore.
QObject.
connect(self.
btAdicionar, QtCore.
SIGNAL("clicked()"), MainWindow.
adicionar)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.btAdicionar = QtGui.QPushButton(self.centralwidget)
self.btAdicionar.setGeometry(QtCore.QRect(90, 40, 91, 21))
self.btAdicionar.setObjectName("btAdicionar")
self.widget = QtGui.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(160, 105, 811, 471))
self.widget.setObjectName("widget")
MainWindow.setCentralWidget(self.centralwidget)
QtCore.QObject.connect(self.btAdicionar, QtCore.SIGNAL("clicked()"), MainWindow.adicionar)
To copy to clipboard, switch view to plain text mode
# thats the class that implements the Ui_MainWindow
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
def adicionar(self):
# here I want to load that widget named a
# I tried this:
# aa = a()
# self.widget.setParent(aa)
# self.widget.show()
# but it didnt work
class MainWindow (QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
def adicionar(self):
# here I want to load that widget named a
# I tried this:
# aa = a()
# self.widget.setParent(aa)
# self.widget.show()
# but it didnt work
To copy to clipboard, switch view to plain text mode
Bookmarks