C++ Class
2019.11.05 22:54

QPushButton 의 커스텀 이미지버튼

조회 수 9371 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

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


List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 QML and Qt Quick Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서 운영자 2019.01.05 110094
100 General and Desktop Qt의 오픈소스 라이센스 소개 file makersweb 2019.12.15 16500
99 Mobile and Embedded Qt for MCU 1.0 릴리즈 makersweb 2019.12.10 4085
98 General and Desktop Qt Marketplace 발표 makersweb 2019.12.02 2867
97 C++ Class QScopedPointer 소개 및 사용법 makersweb 2019.11.29 3253
96 General and Desktop QOpenVirtualkeyboard(Qt 5용 한글 및 영문, 숫자 가상키보드) file makersweb 2019.11.27 5312
95 QML and Qt Quick Qt3D의 QML 타입으로 3D렌더링 file makersweb 2019.11.20 4855
94 Mobile and Embedded 라즈베리파이3에서 Boot to Qt 실행해보기 makersweb 2019.11.13 4426
93 C++ Class Qt애플리케이션 객체(QCoreApplication, QGuiApplication, QApplication) 에 대해서 makersweb 2019.11.11 13929
92 QML and Qt Quick Qt Quick 3D 소개 makersweb 2019.11.09 3613
» C++ Class QPushButton 의 커스텀 이미지버튼 file makersweb 2019.11.05 9371
90 Installation and Deployment qbs 사용 방법(Helloworld) file makersweb 2019.10.23 5191
89 QML and Qt Quick 웹기반 Qt Design Viewer 2 file makersweb 2019.10.23 3771
88 Installation and Deployment Qt Creator에서 Qt의존성 라이브러리 자동복사하기 file makersweb 2019.10.19 5368
87 Mobile and Embedded Qt for Embedded Linux 화면출력 makersweb 2019.10.17 3922
86 Installation and Deployment Windows에서 Qt 설치 따라하기 file makersweb 2019.10.14 34507
85 Installation and Deployment Qbs 프로젝트를 정의하기 위해 사용되는 몇가지 중요한 아이템들 file makersweb 2019.10.13 2388
84 General and Desktop 많은 리소스를 사용하는 Qt프로젝트에서 고려해봐야 할 qmake 옵션 makersweb 2019.10.11 4179
83 Installation and Deployment Qbs에 대한 소개와 설치하는 방법 makersweb 2019.10.09 3634
82 QML and Qt Quick OpenGL 렌더링을 QtQuick과 통합하는 방법 file makersweb 2019.10.01 4638
81 QML and Qt Quick QML내에서의 시그널, 슬롯 시스템 makersweb 2019.09.29 9247
Board Pagination Prev 1 3 4 5 6 7 9 Next
/ 9