개발/PyQt&Python

PyQt 하이퍼링크(QLabel, QPushButton) 달기, 스타일 변경

알 수 없는 사용자 2022. 11. 9.
반응형
QPushButton에 달기
웹사이트 링크 넣기
btn = QPushButton('하이퍼링크 버튼')
btn.clicked.connect(lambda: webbrowser.open('https://jess913.tistory.com'))

QPushButton 클릭이벤트에 lambda: webbrowser.open('주소') 넣기

폴더경로 넣기
folderbtn = QPushButton('폴더 하이퍼링크 버튼')
folderbtn.clicked.connect(lambda: webbrowser.open(os.path.expanduser('~\\Downloads')))

폴더경로를 넣으면 폴더가 열림(예: 사용자 다운로드 폴더 열기)

 

QLabel에 달기
linklb = QLabel()
linklb.setAlignment(Qt.AlignCenter)
#QLabel 스타일
linklb.setStyleSheet('''
            QLabel{
                font-size: 15pt;
                font-family:'Malgun Gothic';
            }
        ''')
linklb.setText(
    '<a href="https://jess913.tistory.com">하이퍼링크 클릭</a>')
linklb.setOpenExternalLinks(True)

QLabel setText에 a태그 넣기

setStyleSheet로 하이퍼링크 스타일 설정

 

QLabel 하이퍼링크 밑줄 없애기 / 글자색 변경
linklb.setText('<a href="https://jess913.tistory.com" style="text-decoration: none;color:#000000;">하이퍼링크 클릭</a>')

a태그 style의 color을 원하는 색상으로 설정

반응형

댓글

💲 추천 글