QT設定QLabelフォントの色を設定します.

1066 ワード

一つはsetPalette()の方法を使うこと.二はスタイルシートを使用します.三はQStyleを使用できます.第四に、いくつかの簡単なHTMLスタイルを使用することができます.  第一に、setPalette()を使用する方法は以下の通りである.
QPalette pe;

pe.setColor(QPalette::WindowText, Qt::red);

QLabel *label = new QLabel(this);

label->setPalette(pe);

label->setText("Hello World");
二つ目のスタイルシートは以下の通りです.
QLabel *label = new QLabel(this);

label->setStyleSheet("background-color: rgb(250, 0, 0);font-size:60px;color:blue");

label->setText("Hello World");
三つ目は、QStyleを使います. 
第四に、簡単なHTML形式を使用します.
QLabel *label = new QLabel(tr("Hello Qt!"));
QLabel *label = new QLabel("

HelloQt!

");
 
Warning: Some スタイル ド not アメリカ the palette for all. drawing、 for instance if they メーク アメリカ 保存先 native 私 engies. This is the case for ぼん the Windows XP Windows Vista、 and the Mac OS X スタイル sheets let あなた perform all. キンズ 保存先 customizations that エリア ディfficult or impossible ト perform using QPalette alone
ですから、できるだけ使い方をします.