Skip to content

Instantly share code, notes, and snippets.

@nrtkbb
Last active February 12, 2016 11:05
Show Gist options
  • Save nrtkbb/fb9dc473df9daada180c to your computer and use it in GitHub Desktop.
Save nrtkbb/fb9dc473df9daada180c to your computer and use it in GitHub Desktop.
## -*- coding: utf-8 -*-
# for maya2015
from PySide import QtGui, QtCore
from maya import OpenMayaUI as omUI
from shiboken import wrapInstance
from PySide.QtUiTools import QUiLoader
from maya.app.general.mayaMixin import MayaQWidgetBaseMixin
def mayaMainWindow():
mainWinPtr = omUI.MQtUtil.mainWindow()
return wrapInstance(long(mainWinPtr), QtGui.QWidget)
class tableWidget(MayaQWidgetBaseMixin, QtGui.QDialog):
uiFile = "c:/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