한국어
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 86926
159 Qt 스마트 포인터 (QSharedPointer, QScopedPointer, QPointer) makersweb 2022.08.18 1280
158 Qt 6.4에 추가될 Qt Quick 3D Physics file makersweb 2022.08.07 395
157 HTTPS URL을 연결할 때 SslHandshakeFailedError 오류 makersweb 2022.07.31 416
156 단일 인스턴스 Qt 응용 프로그램(Single-instance Application) makersweb 2022.06.23 752
155 Qt로 작성된 iOS 앱에서 시리얼 통신 file makersweb 2022.04.30 955
154 VirtualKeyboard 스타일 커스터 마이징 makersweb 2022.03.13 541
153 성능 고려 및 제안 사항 makersweb 2022.03.07 567
152 Binding 타입으로 객체 속성 간 묶기 makersweb 2022.03.04 476
151 Qt Bluetooth Low Energy 개요 makersweb 2022.02.13 728
150 Qt Android 앱에 AdMob 배너달기 file makersweb 2021.12.04 441
149 Qt 6의 C++ 프로퍼티 바인딩 예제 makersweb 2021.11.01 911
148 QML에서 앵커(anchors)로 위치 지정 file makersweb 2021.10.05 4068
147 안드로이드용 Qt 6.2 makersweb 2021.10.02 562
146 Qt 응용프로그램에서 PDF 문서 렌더링 file makersweb 2021.09.23 730
145 QML에서 Websocket 서버와 통신 file makersweb 2021.09.18 901
144 QML 코딩 규칙 makersweb 2021.09.05 3407
143 QML 에서 QR코드 생성 file makersweb 2021.08.20 945
142 앱을 종료할 때 QML 바인딩 오류를 피하는 방법 makersweb 2021.08.08 560
141 Qt 응용프로그램에서 Lottie Animation사용 file makersweb 2021.05.30 942
140 싱글 샷(Single-Shot) 시그널/슬롯 연결 makersweb 2021.05.12 808