How to Change the Background Color of QWidget/fa: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
h1{direction:rtl;text-align:right}. استفاده از Palette
h1{direction:rtl;text-align:right}. استفاده از Palette


<code><br />m_pMyWidget = new QWidget(this);<br /> m_pMyWidget->setGeometry(0,0,300,100);<br /> QPalette Pal(palette());<br /> // set black background<br /> Pal.setColor(QPalette::Background, Qt::black);<br /> m_pMyWidget->setAutoFillBackground(true);<br /> m_pMyWidget->setPalette(Pal);<br /> m_pMyWidget->show();<br /></code>
<code>
m_pMyWidget = new QWidget(this);
m_pMyWidget->setGeometry(0,0,300,100);
QPalette Pal(palette());
// set black background
Pal.setColor(QPalette::Background, Qt::black);
m_pMyWidget->setAutoFillBackground(true);
m_pMyWidget->setPalette(Pal);
m_pMyWidget->show();
</code>


h1{direction:rtl;text-align:right}. استفاده از Style Sheet
h1{direction:rtl;text-align:right}. استفاده از Style Sheet


<code><br />m_pMyWidget = new QWidget(this);<br /> m_pMyWidget->setGeometry(0,0,300,100);<br /> m_pMyWidget->setStyleSheet("background-color:black;");<br /> m_pMyWidget->show();<br /></code>
<code>
m_pMyWidget = new QWidget(this);
m_pMyWidget->setGeometry(0,0,300,100);
m_pMyWidget->setStyleSheet("background-color:black;");
m_pMyWidget->show();
</code>

Revision as of 12:21, 25 February 2015

p{direction:rtl;text-align:right}. برای تغییر رنگ پس زمینه widget ها از کد زیر استفاده می کنیم.

h1{direction:rtl;text-align:right}. استفاده از Palette

m_pMyWidget = new QWidget(this);
 m_pMyWidget->setGeometry(0,0,300,100);
 QPalette Pal(palette());
 // set black background
 Pal.setColor(QPalette::Background, Qt::black);
 m_pMyWidget->setAutoFillBackground(true);
 m_pMyWidget->setPalette(Pal);
 m_pMyWidget->show();

h1{direction:rtl;text-align:right}. استفاده از Style Sheet

m_pMyWidget = new QWidget(this);
 m_pMyWidget->setGeometry(0,0,300,100);
 m_pMyWidget->setStyleSheet("background-color:black;");
 m_pMyWidget->show();