Scala0114 2021. 12. 20. 14:01

1. 스타일 시트 적용

import sys

from PySide6.QtWidgets import QApplication

from widgets import main_window

if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setStyleSheet("TableView { border: 1px solid; font-size: 15px; margin: 0px; padding: 0px; }"
                      "QHeaderView::section:horizontal {"
                      " font-size: 15px;"
                      " font-weight: bold;"
                      " border: 1px solid;"
                      " margin: 0px;"
                      " border-bottom: 2px solid "
                      "}"
                      "QHeaderView::section:horizontal:last {"
                      " font-size: 15px;"
                      " font-weight: bold;"
                      " border: 1px solid;"
                      " margin: 0px;"
                      " border-bottom: 2px solid;"
                      " border-right: 2px solid }"
                      "QHeaderView::section:vertical {"
                      " font-size: 15px;"
                      " font-weight: bold;"
                      " border: 1px solid;"
                      " margin: 0px;"
                      " border-right: 2px solid }"
                      "QTableCornerButton::section {"
                      " border: 1px solid;"
                      " margin: 0px;"
                      "}"
                      )
    screen = main_window.MainWindow()
    sys.exit(app.exec())
  • main.py 에서 QApplication 인스턴스에 위와 같이 스타일시트를 설정하여 앱 내부의 해당 위젯 전체에 적용

 

 

2. 헤더 크기 조정

# 일일 정산서 계산서 위젯
class DayCal(QWidget):
    # 생성자
    def __init__(self):
        super().__init__()
        # 화주명단, 화주별 데이터, 기타 데이터, 결과 데이터를 DB 에서 읽어온다
        self.owner_list = actions.get_daycal_owner_list()
        self.owner_values = actions.get_daycal_owner_values()
        self.other_values = actions.get_daycal_other_values()
        self.result = actions.get_daycal_result()

        # 입력 테이블 생성(화주별 데이터)
        self.input_table = TableView(0)
        self.data_model = DayCalTableModel(self, actions.get_daycal_owner_list(), actions.get_daycal_owner_values())
        self.input_table.setModel(self.data_model)
        self.input_table.verticalHeader().setMinimumWidth(170)

        # 기타 테이블 생성(기타 데이터)
        self.other_table = TableView(1)
        self.other_data_model = DayCalOthersTableModel(self, actions.get_daycal_other_values())
        self.other_table.setModel(self.other_data_model)
        self.other_table.verticalHeader().setMinimumWidth(170)
        self.other_table.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)

        # 결과 테이블 생성
        self.result_table = TableView(2)
        self.result_data_model = DayCalResultTableModel(self, actions.get_daycal_result())
        self.result_table.setModel(self.result_data_model)
        self.result_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        self.init_ui()

	''' 생략 '''
  • input_table과 other_table에 대해 각각 setMinimumWidth 를 호출하여 수평 헤더의 너비를 동일하게 맞춤

  • other_table, result_table에 대해 각각 setSectionResizeMode(QHeaderView.Stretch) 를 호출하여
    오른쪽, 아래쪽으로 남는공간이 없도록 헤더 사이즈를 맞춘다.

  • 같은 작업을 DayCalQueryResult 위젯에서도 적용하여 과거 데이터 조회시에도 같은 형태가 되도록 한다.

 

디자인 변경 전

 

디자인 변경 후

위 작업들을 마치면 위와 같이 테이블의 디자인이 변경된 것을 확인할 수 있다.