Qt_GUI_BG_7_2 - 8BitsCoding/RobotMentor GitHub Wiki

๋ชฉ์ฐจ


QPalette

Working with Palettes:

  • Retrieve(๊ฒ€์ƒ‰) the Palette for the current widget with the Qwidget::palette() method
  • Modify the parts you want customized
  • Reset the palette to the widget using the QWidget::setPalette() method

์˜ˆ์ œ ์‹œ์ž‘ : label์— palette ์ ์šฉํ•˜๊ธฐ

์œ„์™€ ๊ฐ™์€ ๋‹ค์ด์–ผ๋กœ๊ทธ๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ๋ณธ๋‹ค.

๊ทธ๋ฆฌ๊ณ  Palette๋ฅผ ์ˆ˜์ •ํ•ด๋ณด์ž.

#include "QtGuiApplication1.h"

QtGuiApplication1::QtGuiApplication1(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);

	// Retrieve the palette for the label
	QPalette palette = ui.label->palette();

	ui.label->setAutoFillBackground(true);

	// Modify the palette with our changes
	palette.setColor(QPalette::Window, Qt::blue);
	palette.setColor(QPalette::WindowText, Qt::red);

	// Reset the palette to the widget
	ui.label->setPalette(palette);
}