Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created August 25, 2017 22:04
Show Gist options
  • Save Gwith/bb3bce48c298cad7472791b364e35c78 to your computer and use it in GitHub Desktop.
Save Gwith/bb3bce48c298cad7472791b364e35c78 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)
checkbox, checkbox2 = QTableWidgetItem(), QTableWidgetItem()
checkbox.setCheckState(Qt.Unchecked)
checkbox2.setCheckState(Qt.Unchecked)
self.orders_table.setItem(rc, 1, checkbox)
self.orders_table.setItem(rc, 4, checkbox2)
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