https://s3-us-west-2.amazonaws.com/secure.notion-static.com/7b17e566-136e-4231-bb48-6a17591fe1b1/Untitled.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dc928c70-4596-4c2d-98c0-1271b087bf2e/Untitled.png

1. 위젯을 통해 형태 만들기

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3e709f2a-3bf4-404c-865b-d68ca7c2b4ac/Untitled.png

self.label1 = QLabel('한국어', self)
        self.label2 = QLabel('영어', self)
        self.edit1 = QTextEdit(self)
        self.edit2 = QTextEdit(self)
        self.transBtn = QPushButton('번역하기', self)
        self.changeBtn = QPushButton('언어 바꾸기', self)

        vbox1 = QVBoxLayout()
        vbox2 = QVBoxLayout()
        vbox1.addWidget(self.label1,alignment=Qt.AlignCenter)
        vbox1.addWidget(self.edit1)
        vbox2.addWidget(self.label2,alignment=Qt.AlignCenter)
        vbox2.addWidget(self.edit2)

        hbox  = QHBoxLayout()
        hbox.addLayout(vbox1)
        hbox.addLayout(vbox2)

        layout = QVBoxLayout() # 전체적인 레이아웃

        layout.addLayout(hbox) # 수직1,2 -> 수평 레이아웃 ->전체적인 수직 레이아웃
        layout.addWidget(self.transBtn) # 버튼 추가
        layout.addWidget(self.changeBtn) # 버튼 추가
        self.setLayout(layout)
        self.setWindowTitle('구글 번역기')
        self.setGeometry(200, 200, 400, 400)

위젯과 각 위젯을 속성값을 기존에 있던 코드에서 활용해 설정해봅시다

1.1 시그널, 슬롯 연결과 이벤트 처리

Qt Designer에서 시그널과 슬롯을 연결하여 이벤트 처리하는법을 알아봅시다

  1. 프로그램 종료 버튼 생성

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e478d070-9640-4540-8740-edc2abf55b8d/Untitled.png

  1. 시그널 슬롯 추가

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b01bc13c-3216-403f-9071-46ba93eac8b3/Untitled.png

  1. 시그널 슬롯 연결