我有表創建多個選項卡和刪除按鈕的問題。該按鈕應該刪除當前表中的行。我的問題是,它只有當我創建一個以上的新標籤刪除最後創建的錶行。我不能命名錶由於這一事實,我不知道有多少標籤需要。右側按鈕連接與右表
import sys
from PyQt4 import QtGui, QtCore
class Fenster(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.resize(300, 300)
addButton = QtGui.QPushButton(u"Add Tab")
self.connect(addButton, QtCore.SIGNAL("clicked()"), self.addTab)
layout = QtGui.QVBoxLayout()
layout.addWidget(addButton)
self.tab_widget = QtGui.QTabWidget()
self.tab_widget.updatesEnabled()
widget = QtGui.QWidget()
self.tab_widget.addTab(widget, "Tab 1")
widget.setLayout(layout)
self.setCentralWidget(self.tab_widget)
self.show()
def addTab(self):
contents = QtGui.QWidget()
delButton = QtGui.QPushButton(u"Del Row")
self.connect(delButton, QtCore.SIGNAL("clicked()"), self.delRow)
self.table = QtGui.QTableWidget(5, 2)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.table)
layout.addWidget(delButton)
self.tab_widget.addTab(contents, "New Tab")
contents.setLayout(layout)
def delRow(self):
self.table.setRowCount(0)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = Fenster()
window.show()
sys.exit(app.exec_())