본문으로 바로가기

파일의 IT 블로그

  1. Home
  2. 프로그래밍/Python
  3. [PyQT] QLineEdit 숫자만 입력할 수 있게 하기

[PyQT] QLineEdit 숫자만 입력할 수 있게 하기

· 댓글개 · KRFile

 

def set_only_int(self):
    self.onlyInt = QIntValidator()
    self.QLineEdit.setValidator(self.onlyInt)

QMainWindow 가 상속되어 있는 Class에서 다음과 같이 코드 2줄 실행하면 됩니다.

저는 함수로 호출해서 함수로 묶어놨습니다.

QLineEdit 부분에 사용하는 QLineEdit의 객체 이름을 입력해주세요.

 

<참고>

https://stackoverflow.com/questions/13422995/set-qlineedit-to-accept-only-numbers

 

Set QLineEdit to accept only numbers

I have a QLineEdit where the user should input only numbers. So is there a numbers-only setting for QLineEdit?

stackoverflow.com

https://stackoverflow.com/questions/15829782/how-to-restrict-user-input-in-qlineedit-in-pyqt

 

How to restrict user input in QLineEdit in pyqt

I have a QLineEdit and i want to restrict QLineEdit to accept only integers. It should work like inputmask. But I dont want to use inputmask, because if user clicks on QLineEdit cursor will be at the

stackoverflow.com

(원문)

SNS 공유하기
💬 댓글 개
이모티콘창 닫기
울음
안녕
감사해요
당황
피폐

이모티콘을 클릭하면 댓글창에 입력됩니다.