我有一个表,我需要在我的主窗口中添加到网格中。我正在使用 python、sqlite3 和 pyqt。
我的问题是我收到类型错误
QGridLayout.addWidget(QWidget, int, int, int, int, Qt.Alignment alignment=0): 参数 1 有意外的类型 'QSqlTableModel'
我认为这意味着 addWidget 不正确,我不确定它应该是什么?任何想法,将不胜感激。
代码如下:
def CreateStockDBWindow(self):
# Create Table
self.mainLayout = QtGui.QGridLayout()
app = QtGui.QApplication(sys.argv)
self.createConnection()
model = QtSql.QSqlTableModel()
self.initializeModel(model)
# Create Widgets
self.AddButton = QtGui.QPushButton("Add Stock",self)
self.RemoveButton = QtGui.QPushButton("Remove Stock",self)
self.MoreButton = QtGui.QPushButton("More Details",self)
# Create Layouts
self.VLayout = QtGui.QVBoxLayout()
# top bar
# Create Widgets for Top Bar
CompanyNameLabel = QtGui.QLabel("<font size='72'><b>"+"Phoenix Trading"+"</b></font>",self)
searchLabel = QtGui.QLabel("Search:",self)
searchLineEdit = QtGui.QLineEdit("",self)
searchButton = QtGui.QCommandLinkButton("Search",self)
# Create Graphics view
logo = QtGui.QPixmap("logo.jpg")
self.myScene = QtGui.QGraphicsScene()
self.myScene.addPixmap(logo)
self.graphicsView = QtGui.QGraphicsView(self.myScene)
# layouts for top bar
self.TopBarLayout = QtGui.QGridLayout()
self.RHSTopBarLayout = QtGui.QGridLayout()
self.RHSVLayout = QtGui.QGridLayout()
self.TopBarLayout.addWidget(self.graphicsView,0,0)
self.TopBarLayout.addWidget(CompanyNameLabel,0,1)
self.RHSVLayout.addWidget(searchLabel,0,0)
self.RHSVLayout.addWidget(searchLineEdit,0,1)
self.RHSTopBarLayout.addWidget(searchButton,1,0)
self.RHSTopBarLayout.addLayout(self.RHSVLayout,0,0)
self.TopBarLayout.addLayout(self.RHSTopBarLayout,0,2)
# Assemble
self.VLayout.addWidget(self.AddButton)
self.VLayout.addWidget(self.RemoveButton)
self.VLayout.addWidget(self.MoreButton)
self.mainLayout.addLayout(self.TopBarLayout,0,0,1,5)
self.mainLayout.addLayout(self.VLayout,4,1)
self.mainLayout.addWidget(model,4,5)
app.exec
return self.mainLayout