Skip to content

Instantly share code, notes, and snippets.

@altendky
Forked from Gwith/orderconversion.py
Last active August 25, 2017 22:14
Show Gist options
  • Save altendky/05e41b0ca347a4428fa446fcd84348b0 to your computer and use it in GitHub Desktop.
Save altendky/05e41b0ca347a4428fa446fcd84348b0 to your computer and use it in GitHub Desktop.
from PyQt5.QtWidgets import QHeaderView, QTableWidgetItem
from PyQt5.QtCore import Qt
from ui_orderconversion import Ui_OrderConversion
class OrderConversion(Ui_OrderConversion):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# initialize ui
self.setupUi(self)
# set column width by running column_width()
self.column_width()
# if cell is changed run method add_row
self.orders_table.cellChanged.connect(self.add_row)
# dispaly ui
self.show()
def add_row(self, row, column):
'''Add row if order number added to first cell in each column'''
# add needed data to variables
rc = self.orders_table.rowCount()
value = self.orders_table.item(row, column)
value = value.text()
# insert row and checkbox if condition is met
if column == 0 and len(value) == 2:
self.orders_table.insertRow(rc)
for col in (1, 4):
checkbox = QTableWidgetItem()
checkbox.setCheckState(Qt.Unchecked)
self.orders_table.setItem(rc, col, checkbox)
def column_width(self):
'''Adds headers to each column and sets wdith'''
col_headers = ['OrderNum', 'Converted/Printed', 'FaxEmail', 'RequestDate', 'HOT']
self.orders_table.setHorizontalHeaderLabels(col_headers)
self.orders_table.horizontalHeader().setStretchLastSection(True)
self.orders_table.setColumnWidth(1, 120)
self.orders_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment