<repo_name>choiinsung276/PyQtStudy<file_sep>/SignalSlot/createEventHandler.py
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QLCDNumber, QDial, QVBoxLayout,
QPushButton, QHBoxLayout)

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        lcd = QLCDNumber(self)
        dial = QDial(self)
        btn1 = QPushButton('Big', self)
        btn2 = QPushButton('Small', self)

        hbox = QHBoxLayout()
        hbox.addWidget(btn1)
        hbox.addWidget(btn2)
        

        vbox = QVBoxLayout()
        vbox.addWidget(lcd)
        vbox.addWidget(dial)
        vbox.addLayout(hbox)
        self.setLayout(vbox)

        dial.valueChanged.connect(lcd.display)
        btn1.clicked.connect(self.resizeBig)
        btn2.clicked.connect(self.resizeSmall)

        self.setWindowTitle('시그널과슬롯예제')
        self.setGeometry(300,300,200,200)
        self.show()

    def resizeBig(self):
        self.resize(400,500)

    def resizeSmall(self):
        self.resize(200,250)

if __name__=='__main__':
    app=QApplication(sys.argv)
    ex = MyApp()
    sys.exit(app.exec_())<file_sep>/widget/QCheckBox.py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QCheckBox ,QLabel, QVBoxLayout
from PyQt5.QtCore import Qt

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        cb = QCheckBox('박스입니다.',self)
        cb.move(20,20)
        cb.toggle()
        cb.stateChanged.connect(self.changeTitle)

        self.setWindowTitle('안녕하세요')
        self.setGeometry(300,300,300,200)
        self.show()

    def changeTitle(self,state):
        if state ==Qt.Checked:
            self.setWindowTitle('체크박스켰네요.')
            label1 = QLabel('First Label', self)
            label1.setAlignment(Qt.AlignCenter)

            label2 = QLabel('Second Label', self)
            label2.setAlignment(Qt.AlignVCenter)

            font1 = label1.font()
            font1.setPointSize(20)

            font2 = label2.font()
            font2.setFamily('Times New Roman')
            font2.setBold(True)

            label1.setFont(font1)
            label2.setFont(font2)

            layout=QVBoxLayout()
            layout.addWidget(label1)
            layout.addWidget(label2)

            self.setLayout(layout)
            
        else:
            self.setWindowTitle(' ')

if __name__=='__main__':
    app=QApplication(sys.argv)
    ex=MyApp()
    sys.exit(app.exec_())<file_sep>/Dialog/QInputDialog.py
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton, QLineEdit,
QInputDialog)

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.btn = QPushButton('Dalog', self)
        self.btn.move(30, 30)
        self.btn.clicked.connect(self.showDialog)

        self.le = QLineEdit(self)
        self.le.move(120, 35)
        
        self.setWindowTitle("인풋 다이얼로그 예제")
        self.setGeometry(300,300,300,200)
        self.show()

    def showDialog(self):
        text, ok = QInputDialog.getText(self, '인풋 다이얼로그', 'Enter your name: ')

        if ok:
            self.le.setText(str(text)) #str로 해줘야함 

if __name__=='__main__':
    app=QApplication(sys.argv)
    ex = MyApp()
    sys.exit(app.exec_())<file_sep>/widget/absolute.py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        label1 = QLabel('Label1',self)
        label1.move(20,20)
        label2=QLabel('Label2',self)
        label2.move(20,60)

        btn1 = QPushButton('Button1',self)
        btn1.move(100,13)
        btn2= QPushButton('Button2',self)
        btn2.move(80,53)

        self.setWindowTitle('Absolute Positioning')
        self.setGeometry(300,300,400,200)
        self.show()

if __name__=='__main__':
    app=QApplication(sys.argv)
    ex=MyApp()
    sys.exit(app.exec_())
<file_sep>/widget/Style.py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()


    def initUI(self):
        lblred=QLabel('Red')
        lblgreen=QLabel('Green')
        lblblue=QLabel('Blue')

        lblred.setStyleSheet("color:red;"
                             "border-style:solid;"
                             "border-width: 2px;"
                             "border-color: #FA8072;"
                             "border-radius:3px")
        lblgreen.setStyleSheet("color:green;"
                               "background-color:#7FFFD4")
        lblblue.setStyleSheet("color:blue;"
                              "background-color: #87CEFA;"
                              "border-style:dashed;"
                              "border-width: 3px;"
                              "border-color: #1E90FF")

        vbox = QVBoxLayout()
        vbox.addWidget(lblred)
        vbox.addWidget(lblgreen)
        vbox.addWidget(lblblue)

        self.setLayout(vbox)

        self.setWindowTitle('Stylesheet')
        self.setGeometry(300,300,300,200)
        self.show()

if __name__=='__main__':
    app=QApplication(sys.argv)
    ex=MyApp()
    sys.exit(app.exec_())<file_sep>/README.md
# PyQtStudy

## reference

- https://wikidocs.net/book/2165
- https://wikidocs.net/35486
- https://opentutorials.org/module/544/18844
<file_sep>/widget/datetime.py
from PyQt5.QtCore import QDate , Qt, QTime, QDateTime
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow

now = QDate.currentDate()
print(now.toString())
print(now.toString('d.M.yy'))
print(now.toString('dd.MM.yyyy'))
print(now.toString(Qt.ISODate))
print(now.toString(Qt.DefaultLocaleLongDate))
print("=============================")

time = QTime.currentTime()
print(time.toString())
print(time.toString('h.m.s'))
print(time.toString('hh.mm.ss'))
print(time.toString(Qt.DefaultLocaleLongDate))
print(time.toString(Qt.DefaultLocaleShortDate))

print("---------------")
dt = QDateTime.currentDateTime()
print(dt.toString('d.M.yy hh:mm:ss'))
print(dt.toString('dd.MM.yyyy, hh:mm:ss'))
print(dt.toString(Qt.DefaultLocaleLongDate))
print(dt.toString(Qt.DefaultLocaleShortDate))

class MyApp(QMainWindow):
    def __init__(self):
        super().__init__()
        self.date=QDate.currentDate()
        self.initUI()

    def initUI(self):
        self.statusBar().showMessage(self.date.toString(Qt.DefaultLocaleLongDate))
        self.setWindowTitle('Date')
        self.setGeometry(300,300,400,200)
        self.show()

if __name__=='__main__':
    app=QApplication(sys.argv)
    ex=MyApp()
    sys.exit(app.exec_())<file_sep>/widget/BoxLayout.py
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QVBoxLayout

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        okButton = QPushButton('OK')
        cancelButton = QPushButton('Cancel')
        okButton1 = QPushButton('OK1')
        okButton2 = QPushButton('OK2')
        okButton3 = QPushButton('OK3')
        okButton4 = QPushButton('OK4')
        okButton5 = QPushButton('OK5')
        okButton6 = QPushButton('OK6')
        okButton7 = QPushButton('OK7')
        hbox2 = QHBoxLayout()
        hbox2.addStretch(4)
        hbox2.addWidget(okButton1)
        hbox2.addWidget(okButton2)
        hbox2.addWidget(okButton3)
        hbox2.addWidget(okButton4)
        hbox2.addWidget(okButton5)
        hbox2.addStretch(1)

        hbox = QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(okButton)
        hbox.addWidget(cancelButton)
        hbox.addStretch(1)

        vbox = QVBoxLayout()
        vbox.addStretch(3)
        vbox.addLayout(hbox)
        vbox.addStretch(3)
        vbox.addWidget(okButton6)
        vbox.addWidget(okButton7)
        vbox.addLayout(hbox2)
        vbox.addStretch(1)

        self.setLayout(vbox)

        self.setWindowTitle('Box Layout')
        self.setGeometry(300,100,1500,900)
        self.show()

if __name__=='__main__':
    app=QApplication(sys.argv)
    ex = MyApp()
    sys.exit(app.exec_())