def startssevents(self):
# global table
mw=FreeCADGui.getMainWindow()
mdiarea=mw.findChild(QtGui.QMdiArea)
App.activeDocument().Spreadsheet.ViewObject.startEditing(0)
subw=mdiarea.subWindowList()
# print len(subw)
for i in subw:
# print i.widget().metaObject().className()
if i.widget().metaObject().className() == "SpreadsheetGui::SheetView":
sheet = i.widget()
table=sheet.findChild(QtGui.QTableView)
table.clicked.connect(self.clicked)
# table.entered.connect(entered)
table.pressed.connect(self.pressed)
self.table=table
python类QTableView()的实例源码
def startssevents2():
global table
mw=FreeCADGui.getMainWindow()
mdiarea=mw.findChild(QtGui.QMdiArea)
App.activeDocument().Spreadsheet.ViewObject.startEditing(0)
subw=mdiarea.subWindowList()
# print len(subw)
for i in subw:
# print i.widget().metaObject().className()
if i.widget().metaObject().className() == "SpreadsheetGui::SheetView":
sheet = i.widget()
table=sheet.findChild(QtGui.QTableView)
table.clicked.connect(clicked)
# table.entered.connect(entered)
table.pressed.connect(pressed)
# table.itemDelegate().commitData.connect(commitData)
def startssevents(self):
mw=FreeCADGui.getMainWindow()
mdiarea=mw.findChild(QtGui.QMdiArea)
App.activeDocument().Spreadsheet.ViewObject.startEditing(0)
subw=mdiarea.subWindowList()
# print len(subw)
for i in subw:
# print i.widget().metaObject().className()
if i.widget().metaObject().className() == "SpreadsheetGui::SheetView":
sheet = i.widget()
table=sheet.findChild(QtGui.QTableView)
table.clicked.connect(self.clicked)
# table.entered.connect(entered)
table.pressed.connect(self.pressed)
self.table=table
def startssevents2():
''' start events for spreadsheet gui '''
global table
mw=FreeCADGui.getMainWindow()
mdiarea=mw.findChild(QtGui.QMdiArea)
App.activeDocument().Spreadsheet.ViewObject.startEditing(0)
subw=mdiarea.subWindowList()
# print len(subw)
for i in subw:
# print i.widget().metaObject().className()
if i.widget().metaObject().className() == "SpreadsheetGui::SheetView":
sheet = i.widget()
table=sheet.findChild(QtGui.QTableView)
table.clicked.connect(clicked)
# table.entered.connect(entered)
table.pressed.connect(pressed)
# table.itemDelegate().commitData.connect(commitData)
def __init__(self, parent=None, *args):
super(MyTableView, self).__init__(parent, *args)
self.parent = parent
#self.setStyleSheet("QItem { font-size: 10px; }")
self.verticalHeader().setResizeMode(QtGui.QHeaderView.Fixed)
self.verticalHeader().setDefaultSectionSize(20)
#self.resizeColumnsToContents()
#self.resizeRowsToContents()
#self.setStyleSheet("QTableView::item { border: 0px; }")
def setupUi(self, FileAnalyzerDialog):
FileAnalyzerDialog.setObjectName("FileAnalyzerDialog")
FileAnalyzerDialog.resize(904, 505)
self.gridLayoutWidget = QtGui.QWidget(FileAnalyzerDialog)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 20, 881, 471))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtGui.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.gridLayout_2 = QtGui.QGridLayout()
self.gridLayout_2.setObjectName("gridLayout_2")
self.btnRefresh = QtGui.QPushButton(self.gridLayoutWidget)
self.btnRefresh.setObjectName("btnRefresh")
self.gridLayout_2.addWidget(self.btnRefresh, 1, 0, 1, 1)
self.btnExport = QtGui.QPushButton(self.gridLayoutWidget)
self.btnExport.setObjectName("btnExport")
self.gridLayout_2.addWidget(self.btnExport, 0, 0, 1, 1)
self.btnPivot = QtGui.QPushButton(self.gridLayoutWidget)
self.btnPivot.setObjectName("btnPivot")
self.gridLayout_2.addWidget(self.btnPivot, 2, 0, 1, 1)
self.gridLayout.addLayout(self.gridLayout_2, 0, 0, 1, 1)
self.buttonBox = QtGui.QDialogButtonBox(self.gridLayoutWidget)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 1, 1, 1, 1)
self.tableView = QtGui.QTableView(self.gridLayoutWidget)
self.tableView.setObjectName("tableView")
self.gridLayout.addWidget(self.tableView, 0, 1, 1, 1)
self.retranslateUi(FileAnalyzerDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), FileAnalyzerDialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), FileAnalyzerDialog.reject)
QtCore.QMetaObject.connectSlotsByName(FileAnalyzerDialog)
def findTableView(self):
"""
Locate the TableView inside the window
"""
for x in self.window.children()[-1].children(): #last QWidget seems to hold all the children
if type(x) == QtGui.QTableView:
return x
raise Exception('Could not locate QTableView of the window.')
def setupUi(self, MapGrid):
MapGrid.setObjectName("MapGrid")
MapGrid.resize(400, 300)
self.gridLayout_3 = QtGui.QGridLayout(MapGrid)
self.gridLayout_3.setObjectName("gridLayout_3")
self.gridLayout_2 = QtGui.QGridLayout()
self.gridLayout_2.setObjectName("gridLayout_2")
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.comboBoxLeft = QtGui.QComboBox(MapGrid)
self.comboBoxLeft.setObjectName("comboBoxLeft")
self.gridLayout.addWidget(self.comboBoxLeft, 1, 0, 1, 1)
self.comboBoxRight = QtGui.QComboBox(MapGrid)
self.comboBoxRight.setObjectName("comboBoxRight")
self.gridLayout.addWidget(self.comboBoxRight, 1, 1, 1, 1)
self.labelLeft = QtGui.QLabel(MapGrid)
self.labelLeft.setAlignment(QtCore.Qt.AlignCenter)
self.labelLeft.setObjectName("labelLeft")
self.gridLayout.addWidget(self.labelLeft, 0, 0, 1, 1)
self.labelRight = QtGui.QLabel(MapGrid)
self.labelRight.setAlignment(QtCore.Qt.AlignCenter)
self.labelRight.setMargin(0)
self.labelRight.setObjectName("labelRight")
self.gridLayout.addWidget(self.labelRight, 0, 1, 1, 1)
self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
self.btnDelete = QtGui.QPushButton(MapGrid)
self.btnDelete.setObjectName("btnDelete")
self.gridLayout_2.addWidget(self.btnDelete, 2, 0, 1, 1)
self.btnAdd = QtGui.QPushButton(MapGrid)
self.btnAdd.setObjectName("btnAdd")
self.gridLayout_2.addWidget(self.btnAdd, 1, 0, 1, 1)
self.tableView = QtGui.QTableView(MapGrid)
self.tableView.setObjectName("tableView")
self.gridLayout_2.addWidget(self.tableView, 4, 0, 1, 1)
self.gridLayout_3.addLayout(self.gridLayout_2, 0, 0, 1, 1)
self.btnBox = QtGui.QDialogButtonBox(MapGrid)
self.btnBox.setOrientation(QtCore.Qt.Horizontal)
self.btnBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.btnBox.setObjectName("btnBox")
self.gridLayout_3.addWidget(self.btnBox, 1, 0, 1, 1)
self.retranslateUi(MapGrid)
QtCore.QObject.connect(self.btnBox, QtCore.SIGNAL("accepted()"), MapGrid.accept)
QtCore.QObject.connect(self.btnBox, QtCore.SIGNAL("rejected()"), MapGrid.reject)
QtCore.QMetaObject.connectSlotsByName(MapGrid)
def setupUi(self, QueryEditorWindow):
QueryEditorWindow.setObjectName("QueryEditorWindow")
QueryEditorWindow.resize(746, 642)
self.centralwidget = QtGui.QWidget(QueryEditorWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.tableView = QtGui.QTableView(self.centralwidget)
self.tableView.setObjectName("tableView")
self.verticalLayout.addWidget(self.tableView)
self.verticalLayout_2.addLayout(self.verticalLayout)
QueryEditorWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(QueryEditorWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 746, 21))
self.menubar.setObjectName("menubar")
self.menuActions = QtGui.QMenu(self.menubar)
self.menuActions.setObjectName("menuActions")
QueryEditorWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(QueryEditorWindow)
self.statusbar.setObjectName("statusbar")
QueryEditorWindow.setStatusBar(self.statusbar)
self.toolBar = QtGui.QToolBar(QueryEditorWindow)
self.toolBar.setObjectName("toolBar")
QueryEditorWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.actionCommit = QtGui.QAction(QueryEditorWindow)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/standard_icons/save.png"), QtGui.QIcon.Active, QtGui.QIcon.On)
self.actionCommit.setIcon(icon)
self.actionCommit.setObjectName("actionCommit")
self.actionUndo = QtGui.QAction(QueryEditorWindow)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/standard_icons/undo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionUndo.setIcon(icon1)
self.actionUndo.setObjectName("actionUndo")
self.actionCriteria = QtGui.QAction(QueryEditorWindow)
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/standard_icons/filter.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionCriteria.setIcon(icon2)
self.actionCriteria.setObjectName("actionCriteria")
self.actionRefresh = QtGui.QAction(QueryEditorWindow)
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(":/standard_icons/refresh.png"), QtGui.QIcon.Active, QtGui.QIcon.On)
self.actionRefresh.setIcon(icon3)
self.actionRefresh.setObjectName("actionRefresh")
self.menuActions.addAction(self.actionCommit)
self.menuActions.addAction(self.actionUndo)
self.menuActions.addAction(self.actionCriteria)
self.menuActions.addAction(self.actionRefresh)
self.menubar.addAction(self.menuActions.menuAction())
self.toolBar.addAction(self.actionCommit)
self.toolBar.addAction(self.actionUndo)
self.toolBar.addAction(self.actionRefresh)
self.toolBar.addAction(self.actionCriteria)
self.retranslateUi(QueryEditorWindow)
QtCore.QMetaObject.connectSlotsByName(QueryEditorWindow)