Created
June 24, 2016 12:08
-
-
Save anonymous/085c7f01ea1dbc229a93912d5a9c1e23 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
from PyQt5.QtWidgets import QTableWidget, QApplication, QMainWindow, QTableWidgetItem | |
class MyTable(QTableWidget): | |
def __init__(self, r, c): | |
super().__init__(r, c) | |
self.init_ui() | |
def init_ui(self): | |
self.cellChanged.connect(self.c_current) | |
self.show() | |
def c_current(self): | |
row = self.currentRow() | |
col = self.currentColumn() | |
value = self.item(row, col) | |
value = value.text() | |
print("The current cell is ", row, ", ", col) | |
print("In this cell we have: ", value) | |
class Sheet(QMainWindow): | |
def __init__(self): | |
super().__init__() | |
self.form_widget = MyTable(10, 10) | |
self.setCentralWidget(self.form_widget) | |
col_headers = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] | |
self.form_widget.setHorizontalHeaderLabels(col_headers) | |
number = QTableWidgetItem('10') | |
self.form_widget.setCurrentCell(1, 1) | |
self.form_widget.setItem(1, 1, number) | |
self.show() | |
app = QApplication(sys.argv) | |
sheet = Sheet() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can change line:29 col_headers = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] as :
col_headers = list(string.ascii_uppercase[0:10])
(before you do that you should import string)