Issue
I want to combine my Ui generated by QtDesigner. I want to merge it with myplotlib so that everything is in one window. When i run the following code i get an error:
"QWidget::setLayout: Attempting to set QLayout "" on Ui_MainWindow "", which already has a layout
I know that i should connect my canvas layout with something but i dont know with what. I hope you can help me out here:
from PyQt4 import QtCore, QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Ui_MainWindow, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
# this is the Navigation widget
# it takes the Canvas widget and a parent
self.toolbar = NavigationToolbar(self.canvas, self)
# Just some button connected to `plot` method
self.button = QtGui.QPushButton('Plot')
#self.button.clicked.connect(lambda: self.plot(data['time'], data['value']))
#self.button.clicked.connect(self.plot)
self.lineEditMomentum1 = QtGui.QLineEdit()
self.lineEditMomentum1.setMaximumSize(200, 30)
# set the layout
layout = QtGui.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
layout.addWidget(self.button)
layout.addWidget(self.lineEditMomentum1)
self.setLayout(layout)
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(160, 390, 113, 20))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(160, 420, 113, 20))
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(160, 450, 113, 20))
self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
self.lineEdit_4 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_4.setGeometry(QtCore.QRect(160, 480, 113, 20))
self.lineEdit_4.setObjectName(_fromUtf8("lineEdit_4"))
self.lineEdit_5 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_5.setGeometry(QtCore.QRect(160, 510, 113, 20))
self.lineEdit_5.setObjectName(_fromUtf8("lineEdit_5"))
self.lineEdit_6 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_6.setGeometry(QtCore.QRect(160, 540, 113, 20))
self.lineEdit_6.setObjectName(_fromUtf8("lineEdit_6"))
self.lineEdit_7 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_7.setGeometry(QtCore.QRect(650, 430, 113, 20))
self.lineEdit_7.setObjectName(_fromUtf8("lineEdit_7"))
self.lineEdit_8 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_8.setGeometry(QtCore.QRect(650, 460, 113, 20))
self.lineEdit_8.setObjectName(_fromUtf8("lineEdit_8"))
self.lineEdit_9 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_9.setGeometry(QtCore.QRect(650, 490, 113, 20))
self.lineEdit_9.setObjectName(_fromUtf8("lineEdit_9"))
self.lineEdit_10 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_10.setGeometry(QtCore.QRect(650, 520, 113, 20))
self.lineEdit_10.setObjectName(_fromUtf8("lineEdit_10"))
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(60, 390, 61, 16))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(60, 420, 61, 16))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(60, 450, 71, 16))
self.label_3.setObjectName(_fromUtf8("label_3"))
self.label_4 = QtGui.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(60, 480, 81, 16))
self.label_4.setObjectName(_fromUtf8("label_4"))
self.label_5 = QtGui.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(40, 510, 111, 20))
self.label_5.setObjectName(_fromUtf8("label_5"))
self.label_6 = QtGui.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(40, 540, 111, 16))
self.label_6.setObjectName(_fromUtf8("label_6"))
self.label_7 = QtGui.QLabel(self.centralwidget)
self.label_7.setGeometry(QtCore.QRect(585, 430, 51, 20))
self.label_7.setObjectName(_fromUtf8("label_7"))
self.label_8 = QtGui.QLabel(self.centralwidget)
self.label_8.setGeometry(QtCore.QRect(585, 460, 51, 20))
self.label_8.setObjectName(_fromUtf8("label_8"))
self.label_9 = QtGui.QLabel(self.centralwidget)
self.label_9.setGeometry(QtCore.QRect(630, 400, 131, 16))
self.label_9.setObjectName(_fromUtf8("label_9"))
self.label_10 = QtGui.QLabel(self.centralwidget)
self.label_10.setGeometry(QtCore.QRect(600, 490, 31, 16))
self.label_10.setObjectName(_fromUtf8("label_10"))
self.label_11 = QtGui.QLabel(self.centralwidget)
self.label_11.setGeometry(QtCore.QRect(580, 520, 71, 16))
self.label_11.setObjectName(_fromUtf8("label_11"))
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(300, 370, 251, 91))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush)
brush = QtGui.QBrush(QtGui.QColor(63, 63, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 170))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(37, 88, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Shadow, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.NoRole, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush)
brush = QtGui.QBrush(QtGui.QColor(63, 63, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 170))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(37, 88, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.NoRole, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(127, 127, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush)
brush = QtGui.QBrush(QtGui.QColor(63, 63, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 170))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.NoRole, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 220))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipBase, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipText, brush)
self.pushButton.setPalette(palette)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(300, 460, 251, 91))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.label.setText(_translate("MainWindow", "Momentum 1", None))
self.label_2.setText(_translate("MainWindow", "Momentum 2", None))
self.label_3.setText(_translate("MainWindow", "Friction ratio 1", None))
self.label_4.setText(_translate("MainWindow", "Friction ratio 2", None))
self.label_5.setText(_translate("MainWindow", "Number of teeth, N1", None))
self.label_6.setText(_translate("MainWindow", "Number of teeth, N2", None))
self.label_7.setText(_translate("MainWindow", "Initial time", None))
self.label_8.setText(_translate("MainWindow", "Final time", None))
self.label_9.setText(_translate("MainWindow", "Differential parameters", None))
self.label_10.setText(_translate("MainWindow", "Step", None))
self.label_11.setText(_translate("MainWindow", "Initial angle", None))
self.pushButton.setText(_translate("MainWindow", "Plot", None))
self.pushButton_2.setText(_translate("MainWindow", "Set Default Values", None))
Solution
A minimal stand-alone program that still produces your error is:
import sys
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Ui_MainWindow, self).__init__(parent)
layout = QtGui.QVBoxLayout()
self.setLayout(layout)
if __name__ == "__main__":
qApp = QtGui.QApplication(sys.argv)
main_window = Ui_MainWindow()
main_window.show()
sys.exit(qApp.exec_())
As you can see it is unrelated to integrating matplotlib in PyQt. The problem is that QMainWindow
must have a central widget which acts as a container for all your child widgets. This central widget has its own layout, the layout of the QMainWindow
is for toolbars and dock widgets (see the illustration in http://doc.qt.io/qt-4.8/qmainwindow.html). Note that you should add toolbars with the addToolbar()
method.
The fix to your error is thus:
import sys
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Ui_MainWindow, self).__init__(parent)
self.main_widget = QtGui.QWidget(self)
self.setCentralWidget(self.main_widget)
layout = QtGui.QVBoxLayout()
self.main_widget.setLayout(layout)
# The main_widget is a container to which you
# can add your child widgets here...
if __name__ == "__main__":
qApp = QtGui.QApplication(sys.argv)
main_window = Ui_MainWindow()
main_window.show()
sys.exit(qApp.exec_())
Now, your code example contains another error, which is the one that @tcaswell provided an answer for. If you build the fix into your program you will see that the figure canvas will end up in its own, separate window.
Again, a minimal-ish example is:
import sys
from PyQt4 import QtCore, QtGui
from matplotlib.backends.backend_qt4agg import \
FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import \
NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt
class Ui_MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Ui_MainWindow, self).__init__(parent)
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
# use addToolbar to add toolbars to the main window directly!
self.toolbar = NavigationToolbar(self.canvas, self)
self.addToolBar(self.toolbar)
self.button = QtGui.QPushButton('Plot')
self.lineEditMomentum1 = QtGui.QLineEdit()
self.lineEditMomentum1.setMaximumSize(200, 30)
self.main_widget = QtGui.QWidget(self)
self.setCentralWidget(self.main_widget)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.canvas)
layout.addWidget(self.button)
layout.addWidget(self.lineEditMomentum1)
self.main_widget.setLayout(layout)
if __name__ == "__main__":
qApp = QtGui.QApplication(sys.argv)
main_window = Ui_MainWindow()
main_window.show()
sys.exit(qApp.exec_())
When combining matplotlib in PyQt, don't use the matlab-like interface of the pyplot
module at all. Use the matplotlib classes directly.
Change plt.figure()
in Figure()
like so:
import sys
from PyQt4 import QtCore, QtGui
from matplotlib.backends.backend_qt4agg \
import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg \
import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
class Ui_MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Ui_MainWindow, self).__init__(parent)
self.figure = Figure() # don't use matplotlib.pyplot at all!
self.canvas = FigureCanvas(self.figure)
# use addToolbar to add toolbars to the main window directly!
self.toolbar = NavigationToolbar(self.canvas, self)
self.addToolBar(self.toolbar)
self.button = QtGui.QPushButton('Plot')
self.lineEditMomentum1 = QtGui.QLineEdit()
self.lineEditMomentum1.setMaximumSize(200, 30)
self.main_widget = QtGui.QWidget(self)
self.setCentralWidget(self.main_widget)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.canvas)
layout.addWidget(self.button)
layout.addWidget(self.lineEditMomentum1)
self.main_widget.setLayout(layout)
if __name__ == "__main__":
qApp = QtGui.QApplication(sys.argv)
main_window = Ui_MainWindow()
main_window.show()
sys.exit(qApp.exec_())
Finally, you might consider to create your programs without using the Qt Designer. You will gain a lot of insight by building them from scratch, your code will be more readable and it will be easier to make minimal working examples of your problems. I think the extra time it takes to type the widget statements will pay itself back.
Answered By - titusjan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.