QDateEdit, QTimeEdit, QDateTimeEdit 위젯 > Pyside6 - GUI for Python

본문 바로가기

사이트 내 전체검색

이전으로Pyside6 - GUI for Python

QDateEdit, QTimeEdit, QDateTimeEdit 위젯

페이지정보

글쓴이 관리자 조회 21,511 조회 날짜 19-12-13 15:32 / U:22-12-05 02:14
댓글 0댓글

SNS 공유

  • 트위터로 보내기
  • 페이스북으로 보내기
  • 구글플러스로 보내기

내용

QDateEdit, QTimeEdit, QDateTimeEdit 위젯

 

 

QDateEdit, - 날짜 추출 및 세팅, QCalendarWidget과 기능 겹침

QTimeEdit - 시간 추출 및 세팅

QDateTimeEdit - 날짜와 시간 모두 추출 및 세팅, QDateEdit + QTimeEdit

 

UI file

1269731307_1576270585.1881.png

 

 

1. 날짜, 시간, 날짜-시간 받아오기

 

# 날짜 메서드 date()

d = UI_set.dateEdit.date() 

 

# 시간 메서드 time()
t = UI_set.timeEdit.time()

 

# 날짜-시간 메서드 dateTime()
dt = UI_set.dateTimeEdit.dateTime()

 

각각의 표현 방법은 아래와 같다.

print(d.toString())
print(t.toString())
print(dt.toString())
print(d.toString("yyyy-MM-dd"))
print(t.toString("H:m:s a"))
print(dt.toString("yyyy-MM-dd H:m:s a"))
금 12 13 2019
14:23:12
금 12 13 15:12:10 2019
2019-12-13
14:23:12 오후
2019-12-13 15:12:10 오후

 

toString의 QStrng format은 아래와 같다. 아래의 표현을 참고하여 원하는 모양으로 데이터를 추출하면 된다.

 

1) 날짜에 관련된 표현

Expression Output
d the day as number without a leading zero (1 to 31)
dd the day as number with a leading zero (01 to 31)
ddd the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses the system locale to localize the name, i.e. QLocale::system().
dddd the long localized day name (e.g. 'Monday' to 'Sunday'). Uses the system locale to localize the name, i.e. QLocale::system().
M the month as number without a leading zero (1-12)
MM the month as number with a leading zero (01-12)
MMM the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses the system locale to localize the name, i.e. QLocale::system().
MMMM the long localized month name (e.g. 'January' to 'December'). Uses the system locale to localize the name, i.e. QLocale::system().
yy the year as two digit number (00-99)
yyyy the year as four digit number

 

2) 시간에 관련된 표현

Expression Output
h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
H the hour without a leading zero (0 to 23, even with AM/PM display)
HH the hour with a leading zero (00 to 23, even with AM/PM display)
m the minute without a leading zero (0 to 59)
mm the minute with a leading zero (00 to 59)
s the whole second without a leading zero (0 to 59)
ss the whole second with a leading zero where applicable (00 to 59)
z the fractional part of the second, to go after a decimal point, without trailing zeroes (0 to 999). Thus "s.z" reports the seconds to full available (millisecond) precision without trailing zeroes.
zzz the fractional part of the second, to millisecond precision, including trailing zeroes where applicable (000 to 999).
AP or A use AM/PM display. A/AP will be replaced by either "AM" or "PM".
ap or a use am/pm display. a/ap will be replaced by either "am" or "pm".
t the timezone (for example "CEST")

출처 : https://doc.qt.io/archives/qt-5.13/qdatetime.html#toString

 

 

2. 날짜, 시간 세팅하기

 

- QDateEdit 

setDate(QtCore.QDate(년, 월, 일)) - 년, 월, 일은 int 이다.

 

- QTimeEdit

setTime(QtCore.QTime(시, 분, 초, 마이크로초)) - 시, 분, 초, 마이크로초는 int이다.

 

# QDateTiemEdit은 date와 time만 따로 설정할 수 있다.

- QDateTimeEdit

setDateTime(QtCore.QDateTime(년, 월, 일, 시, 분, 초)) - 년, 월, 일, 시, 분, 초는 int이다.

setDate(QtCore.QDate(년, 월, 일)) - 년, 월, 일은 int 이다.

setTime(QtCore.QTime(시, 분, 초, 마이크로초)) - 시, 분, 초, 마이크로초는 int이다.

 

 

사용법

 

UI_set.timeEdit.setTime(QtCore.QTime(14,23,12,45))
UI_set.dateEdit.setDate(QtCore.QDate(2019,12,15))

       
UI_set.dateTimeEdit.setDateTime(QtCore.QDateTime(2019, 12, 15, 15, 12, 10))

UI_set.dateTimeEdit.setDate(QtCore.QDate(2019, 12, 15))
UI_set.dateTimeEdit.setTime(QtCore.QTime(14,23,12,45))

 

 

 

 

출처 : 

QDateEdit - https://doc.qt.io/qtforpython/PySide6/QtWidgets/QDateEdit.html

QTimeEdit - https://doc.qt.io/qtforpython/PySide6/QtWidgets/QTimeEdit.html

QDateTimeEdit - https://doc.qt.io/qtforpython/PySide6/QtWidgets/QDateTimeEdit.html

댓글목록

댓글이 없습니다

게시물 검색
총 12 건 , 1 페이지
올서베이넷
무료 온라인 설문 사이트
OVITII
웹 프레젠테이션 도구
Copyright © JBMPA.com All rights reserved.
사이트 언어 선택
PC 보기