Skip to content

Instantly share code, notes, and snippets.

@kywthiha
Forked from anonymous/spread2.py
Created November 17, 2019 10:33
Show Gist options
  • Save kywthiha/db9afa8d47199eb83db61f7036aa567c to your computer and use it in GitHub Desktop.
Save kywthiha/db9afa8d47199eb83db61f7036aa567c to your computer and use it in GitHub Desktop.
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