- Widget
- 참고 문헌
PyQt5를 정리 합니다.
Widget
QMainWinow
obj.setGeometry(x, y, width, height)
QStatusBar
obj.showMessage(~)
QPushButton
obj.move(x, y)
obj.resize(width, height)
obj.clicked.connect(~)
QLabel
obj.text()
obj.setText(~)
obj.clear()
QLineEdit
obj.textChanged.connect(~)
obj.returnPressed.connect(~) #--- Enter key 입력시 호출
QGroupBox
QRadioButton
obj.setChecked(True)
obj.clicked.connect(~)
QCheckBox
obj.stateChanged.connect(~)
QSpinBox
obj.setMinimum(~)
obj.setSingleStep(~)
obj.setMaximum(~)
obj.valueChanged.connect(~)
QTableWidget
self.tableWidget = QTableWidget(self)
self.tableWidget.resize(400, 200)
self.tableWidget.setColumnCount(3)
self.tableWidget.setRowCount(2)
self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers) #--- Read only
header_cols = ['성별', '나이']('이름',)
self.tableWidget.setHorizontalHeaderLabels(header_cols)
self.tableWidget.setVerticalHeaderLabels(['유관순']('이순신',))
row = 0
item = QTableWidgetItem("이순신")
item.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
self.tableWidget.setItem(row, 0, item)
self.tableWidget.setItem(row, 1, QTableWidgetItem("남성"))
self.tableWidget.setItem(row, 2, QTableWidgetItem("28"))
row = row + 1
item = QTableWidgetItem("유관순")
item.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
self.tableWidget.setItem(row, 0, item)
self.tableWidget.setItem(row, 1, QTableWidgetItem("여성"))
self.tableWidget.setItem(row, 2, QTableWidgetItem("32"))
self.tableWidget.resizeColumnsToContents()
self.tableWidget.resizeRowsToContents()
layout 공통 사항
layout_group.addStretch(1) #--- 레이아웃 내부 정렬
layout.setStretchFactor(layout_left, 1) #--- 레이아웃 상대 크기 지정
layout.setStretchFactor(layout_right, 3) #--- 레이아웃 상대 크기 지정
QVBoxLayout, QHBoxLayout
self.setCentralWidget(QtWidgets.QWidget(self))
self.textEdit = QTextEdit()
self.pushButton = QPushButton('저장')
layout = QVBoxLayout()
layout = QHBoxLayout()
layout.addWidget(self.textEdit)
layout.addWidget(self.pushButton)
# self.setLayout(layout)
self.centralWidget().setLayout(layout)
QGridLayout
self.setCentralWidget(QtWidgets.QWidget(self))
layout = QGridLayout()
layout.addWidget(QLabel("아이디"), 0, 0)
layout.addWidget(QTextEdit(), 0, 1)
layout.addWidget(QPushButton('로그인'), 0, 2)
layout.addWidget(QLabel("비밀번호"), 1, 0)
layout.addWidget(QTextEdit(), 1, 1)
self.centralWidget().setLayout(layout)
QFileDialog, QInputDialog
fname = QFileDialog.getOpenFileName(self)
fname[0](0.md)
(rtInt, ok) = QInputDialog.getInt(self, '수량', '수량을 입력 하세요.') #--- ~.getDouble()
if ok:
rtInt
(rtStr, ok) = QInputDialog.getText(self, '이름', '이름을 입력 하세요.')
if ok:
rtStr
(rtStr, ok) = QInputDialog.getItem(self, '이름', '이름을 선택 하세요.',
['홍길동', '유관순']('이순신',), 0, False)
if ok:
rtStr
사용자 정의 Dialog
def show_dialog(self):
dlg = MyDialog()
dlg.exec_()
print(dlg.name)
class MyDialog(QDialog):
def __init__(self):
super.__init__()
self.name = None
self.setWindowTitle("My Dialog")
self.setWindowIcon(QIcon("~.png"))
self.setGeometry(100, 100, 200, 200)
self.edit = QLineEdit()
self.button = QPushButton("아이디 확인")
self.button.clicked.connect(self.button_clicked)
layout = QVBoxLayout()
layout.addWidget(self.edit)
layout.addWidget(self.button)
self.setLayout(layout)
def button_clicked(self):
self.name = self.edit.text()
self.close()
FigureCanvas
self.canvas = FigureCanvas(plt.Figure()) #--- Canvas > Figure > Subplot
self.canvas.figure.clear() #--- Figure 지우기
self.ax = self.canvas.figure.add_subplot(1, 1, 1)
self.ax.plot([2, 3, 4, 3](1,))
self.ax.grid()
self.ax.clear() #--- Subplot 지우기
self.ax.plot([4, 5, 2, 3, 4](5,))
self.ax.grid()
self.canvas.draw()
참고 문헌
분류: _프로그램_언어
최종 수정일: 2024-09-30 12:26:18
이전글 :
다음글 :