I have been trying to no avail to load a ui file and insert it into a tabWidget as a new tab. I commented out a try that I thought would work, I was wrong. I have tried several different ways but I always seem to get the same error.
The original gui MainWindow is a qt ui file as well. If I just do a simple show the ui it does a flash and is gone. Otherwise the error I get is self is
Traceback (most recent call last):
File "test5.py", line 19, in createInvoice
createInv()
File "test5.py", line 38, in createInv
ui.tabWidget.addTab(self, invoice)
NameError: global name 'self' is not defined
#!/usr/bin/python
import sys
from PyQt4 import QtCore, QtGui, uic, QtSql
class DemoImpl(QtGui.QMainWindow):
def __init__(self, *args):
super(DemoImpl, self).__init__(*args)
uic.loadUi('K:\QTProjects\pos\mainwindow.ui', self)
self.btnLogin.clicked.connect(self.createConnection)
self.btnCreateInvoice.clicked.connect(self.createInvoice)
def createConnection(self):
createConn()
def createInvoice(self):
createInv()
def createConn():
db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
db.setDatabaseName(':memory:')
if not db.open():
QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Cannot open database"), QtGui.qApp.tr("Unable to establish a database connection.\nThis example needs SQLite support. Please read the Qt SQL driver documentation for information how to build it.\n\nClick Cancel to exit."), QtGui.QMessageBox.Cancel)
return False
else:
QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Cannot open database"), QtGui.qApp.tr("Database Connected"), QtGui.QMessageBox.Cancel)
return True
def createInv():
invoice = uic.loadUi('K:\QTProjects\pos\invoicetoolbox.ui')
QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Loaded Invoice"), QtGui.qApp.tr("Loaded Invoice"), QtGui.QMessageBox.Ok)
print invoice
# ui.invoice.show()
# ui.tabWidget.addTab(self, invoice)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
ui = DemoImpl()
ui.show()
sys.exit(app.exec_())