我已尝试将整合按钮edit
加入column "A1"
(similar like here)但遗憾的是到目前为止还没有成功。
我想将edit button
添加到column "A1"
的每一行中,只要未按下编辑按钮,就无法编辑行。
下一步我尝试过但没有找到cell "A2"
显示在表格层(cell "B1"
)中的解决方案,但其内容已禁用编辑。
# -*- coding: utf-8 -*-
import sqlite3 as sql
from PyQt4 import QtCore, QtGui
import sys, os
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
# Tabs & QWidget
self.tabs = QtGui.QTabWidget(self)
self.general = QtGui.QWidget()
self.layers = QtGui.QWidget()
self.tabs.addTab(self.general, "General")
self.tabs.addTab(self.layers, "Layers")
cWidget = QtGui.QWidget(self)
self.setCentralWidget(cWidget)
# QTableWidget
self.general_table = QtGui.QTableWidget(self.general)
self.layers_table = QtGui.QTableWidget(self.layers)
# Geometry
self.tabs.setGeometry(0, 0, 1500, 500)
self.general_table.setGeometry(0,0,1490,500)
self.layers_table.setGeometry(0,0,1490,500)
self.setGeometry(100,100,1520,720)
self.setFixedSize(1520, 720)
self.setHeader()
# Set Column Width and resize the conctext automatically
header = self.general_table.horizontalHeader()
header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
header.setStretchLastSection(True)
header = self.layers_table.horizontalHeader()
header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
header.setStretchLastSection(True)
# PushButton
add_record = QtGui.QPushButton("Add Record")
delete_record = QtGui.QPushButton("Delete Record")
# Layout
layout = QtGui.QVBoxLayout(cWidget)
layout.addWidget(self.tabs)
layout.addWidget(add_record)
layout.addWidget(delete_record)
# Connect SIGNAL
self.connect(add_record, QtCore.SIGNAL('clicked()'), self.addRecord)
self.connect(delete_record, QtCore.SIGNAL('clicked()'), self.deleteRecord)
def whatTab(self):
current_index = self.tabs.currentIndex()
self.tabs.currentWidget()
return current_index
def addRecord(self):
rcount_general = self.general_table.rowCount()
self.general_table.insertRow(rcount_general)
self.layers_table.insertRow(rcount_general)
self.fullNone(rcount_general)
def deleteRecord(self):
self.general_table.removeRow(self.general_table.currentIndex().row())
self.layers_table.removeRow(self.general_table.currentIndex().row())
def setHeader(self):
# General
self.general_table.setRowCount(1)
self.general_table.setColumnCount(6)
self.general_table.setHorizontalHeaderLabels(["A1", "A2", "A3", "A4",
"A5", "A6)"])
# Layers
self.layers_table.setRowCount(1)
self.layers_table.setColumnCount(8)
self.layers_table.setHorizontalHeaderLabels(["B1", "B2", "B3", "B4",
"B5", "B6", "B8", "B9"])
self.fullNone(0)
def fullNone(self, row):
for col in range(0, 6, 1):
self.general_table.setItem(row, col, QtGui.QTableWidgetItem("None"))
for col in range(0, 8, 1):
self.layers_table.setItem(row, col, QtGui.QTableWidgetItem("None"))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())