Qt_GUI_BG_7_3 - 8BitsCoding/RobotMentor GitHub Wiki

목차


Style Sheets

  • Style sheets are textual specifications that can be set on the whole application using QApplication::setStyleSheet() or on a specific widget (and its children) using QWidget::setStyleSheet()

Example

QLineEdit {background: yellow}

  • Style sheets consit of a sequence of style rules.
  • A Style rule is made up of a selection and declaration

예제 : Qt Designer에서 Style Sheet 설정

위 다이얼로그를 기반으로 두 가지 방법으로 수정해 본다.

첫 번째로 Qt Designer에서 해당 label을 우클릭 후 Style Sheet 수정을 누른다.


예제 : 모든 다이얼로그에 동일하게 Style Sheet 적용

#include "QtGuiApplication2.h"
#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);

    // set style sheet application wise.
	a.setStyleSheet("QPushButton{color : red; background-color : white;}");
	QtGuiApplication2 w;
	w.show();
	return a.exec();
}

예제 : 특정 컨트롤에만 Style Sheet를 적용하고 싶다면?

#include "QtGuiApplication2.h"

QtGuiApplication2::QtGuiApplication2(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	ui.special_button->setStyleSheet("QPushButton{background-color : red;}");
}