Last active
August 29, 2015 14:00
-
-
Save fereria/11537930 to your computer and use it in GitHub Desktop.
TableWidgetTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## -*- coding: utf-8 -*- | |
from PySide import QtGui, QtCore | |
from Shiboken.shiboken import wrapInstance | |
from maya import OpenMayaUI as omUI | |
from PySide.QtUiTools import QUiLoader | |
import Shiboken.shiboken as shiboken | |
def mayaMainWindow(): | |
mainWinPtr = omUI.MQtUtil.mainWindow() | |
return shiboken.wrapInstance(long(mainWinPtr), QtGui.QWidget) | |
class tableWidget(QtGui.QDialog): | |
uiFile = "E:/Bitbucket/scripttestdev/Qt/table.ui" | |
def __init__(self): | |
super(tableWidget, self).__init__(mayaMainWindow()) | |
self.setWidget() | |
layout = QtGui.QVBoxLayout() | |
layout.addWidget(self.ui) | |
self.setLayout(layout) | |
#右クリック時のメニュー | |
self.ui.testTable.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) | |
addRowMenu = QtGui.QAction(self.ui.testTable) | |
addRowMenu.setText("addRow") | |
addRowMenu.triggered.connect(self.addRow) | |
self.ui.testTable.addAction(addRowMenu) | |
addColMenu = QtGui.QAction(self.ui.testTable) | |
addColMenu.setText("addColumn") | |
addColMenu.triggered.connect(self.addColumn) | |
self.ui.testTable.addAction(addColMenu) | |
width = self.ui.geometry().width() | |
height = self.ui.geometry().height() | |
#Windowサイズ変更 | |
self.resize(width,height) | |
def setWidget(self): | |
qLoader = QUiLoader() | |
qFile = QtCore.QFile(self.uiFile) | |
qFile.open(QtCore.QFile.ReadOnly) | |
self.ui = qLoader.load(qFile,self) | |
qFile.close() | |
def addRow(self): | |
rowCount = self.ui.testTable.rowCount() | |
colCount = self.ui.testTable.columnCount() | |
self.ui.testTable.setRowCount(rowCount+1) | |
for i in range(colCount): | |
self.ui.testTable.setItem(rowCount,i,QtGui.QTableWidgetItem(str(i))) | |
def addColumn(self): | |
columnCount = self.ui.testTable.columnCount() | |
rowCount = self.ui.testTable.rowCount() | |
self.ui.testTable.setColumnCount(columnCount+1) | |
for i in range(rowCount): | |
self.ui.testTable.setItem(i,columnCount,QtGui.QTableWidgetItem(str(i))) | |
if __name__ == "__main__": | |
app = tableWidget() | |
app.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment