한국어
Qt
 

C++ Class Qt 응용프로그램을 개발할 때 사용자정의 이미지버튼을 만드는 방법은 여러가지가 있지만 기본은 QWidget을 서브클래싱하여 구현한다. 위젯 기반의 Qt응용프로그램 개발에서 자주 사용되는 QPushButton이 있는데 QPushButton 클래스 또한 QWidget 을 기반으로 두고있음을 알 수 있다.

 

간단한 이미지 버튼을 만드는 방법중에 QPushButton을 사용하는 방법으로 Qt Style Sheet를 이용하면 간단하게 구현할 수 있다. Qt Style Sheets는 위젯의 모양을 사용자 정의하여 다양한 형태로 바꿀 수 있다. https://doc.qt.io/qt-5/stylesheet-reference.html

 

다음은 버튼을 클릭하지 않았을 때의 normal상태와 클릭했을때의 pressed 상태의 이미지 버튼을 구현하는 간단한 예제이다.

QPushButton *mybutton = new QPushButton(this);

mybutton->setStyleSheet(
            "                                  \
            QPushButton {                      \
                border-image: url(:/normal.png); \
                background-repeat: no-repeat;  \
            }                                  \
                                                \
            QPushButton:pressed {              \
                border-image: url(:/pressed.png); \
                background-repeat: no-repeat;  \
            }                                  \
            ");

mybutton->setGeometry(0, 0, 45, 131);

 

다음과 같이 간단한 사용자 정의 이미지 버튼을 만들 수 있다.

makerswebImageButton.gif

번호 제목 글쓴이 날짜 조회 수
공지 Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서 운영자 2019.01.05 86187
159 clazy 로 13개의 시그널, 슬롯 오류 해결 makersweb 2022.08.23 579
158 QML과 코루틴(Coroutines) makersweb 2020.11.03 582
157 최초의 Qt 6.0 스냅샷 제공 (First Qt 6.0 Snapshot Available) j2doll 2020.06.21 594
156 QProcess 보안 권고 리뷰 file makersweb 2022.09.18 602
155 QML의 사용자 정의 Image makersweb 2023.09.17 606
154 Qt Marketplace 발표 makersweb 2019.12.02 617
153 Embedded Linux 에서 Qt 및 Graphics Stack file 운영자 2020.05.27 619
152 OpacityMask 예제 file makersweb 2023.01.26 658
151 Qt Bluetooth Low Energy 개요 makersweb 2022.02.13 678
150 Qt 응용프로그램에서 PDF 문서 렌더링 file makersweb 2021.09.23 679
149 Qt5Compat 라이브러리를 사용하여 Qt5에서 Qt6로 포팅 [2] makersweb 2020.12.05 685
148 클라우드용 Qt file makersweb 2024.01.16 697
147 단일 인스턴스 Qt 응용 프로그램(Single-instance Application) makersweb 2022.06.23 707
146 QML에서 D-Bus 통신 file makersweb 2023.03.15 713
145 2020년에 변경되는 Qt 오퍼 (Qt offering changes 2020) [2] j2doll 2020.01.31 723
144 Qt for MCU 1.0 릴리즈 makersweb 2019.12.10 753
143 싱글 샷(Single-Shot) 시그널/슬롯 연결 makersweb 2021.05.12 757
142 Q_D매크로와 d-pointer file makersweb 2019.05.07 762
141 Qt Bluetooth 관련 기능 확인 사항 makersweb 2018.07.10 770
140 Qt 6 에서 프로퍼티 바인딩 makersweb 2021.04.03 776