한국어
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