from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt
import os
ch = []
class Window(QtGui.QWidget):
def __init__(self, rows, columns):
QtGui.QWidget.__init__(self)
self.table = QtGui.QTableWidget(rows, columns, self)
layout = QtGui.QVBoxLayout(self)
for row in range(rows):
qwidget = QtGui.QWidget()
checkbox = QtGui.QCheckBox()
checkbox.setCheckState(QtCore.Qt.Unchecked)
qhboxlayout = QtGui.QHBoxLayout(qwidget)
qhboxlayout.addWidget(checkbox)
qhboxlayout.setAlignment(Qt.AlignCenter)
qhboxlayout.setContentsMargins(0, 0, 0, 0)
self.table.setCellWidget(row, 0, qwidget)
for filename in os.listdir("C:\\Python27\\Codes\\"):
files = os.path.splitext(filename)[0]
ch.append(files)
self.table.setItem(row, 1, QtGui.QTableWidgetItem(str(files)))
layout.addWidget(self.table)
self.button = QtGui.QPushButton()
self.button.setObjectName("loadButton")
#layout.addWidget(self.table)
layout.addWidget(self.button)
self.button.clicked.connect(self.ButtonClicked)
def ButtonClicked(self):
checked_list = []
for i in range(self.table.rowCount()):
if self.table.cellWidget(i, 0).findChild(type(QtGui.QCheckBox())).isChecked():
checked_list.append(self.table.item(i, 1).text())
print checked_list
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window(50, 2)
window.resize(350, 300)
window.show()
sys.exit(app.exec_())