效果:
源码
void StickyTopicPage::init()
{
this->setWindowFlags(Qt::Dialog |Qt::FramelessWindowHint);
this->resize(800,480);
// 设置背景图片
setAutoFillBackground(true); // 这句要加上, 否则可能显示不出背景图.
QPalette palette = this->palette();
//palette.setColor(QPalette::Window, Qt::red); // 设置背景色
//palette.setBrush(this->backgroundRole(), Qt::black);// 设置背景色
palette.setBrush(QPalette::Window,
QBrush(QPixmap(":/image/lockScreen.jpg").scaled( // 缩放背景图.
this->size(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation))); // 使用平滑的缩放方式
this->setPalette(palette);
m_pLabel = new QLabel("Controlled Computer",this);
m_pLabel->setAlignment(Qt::AlignCenter);
QFont font ("Microsoft YaHei", 50, 100); //第一个属性是字体(微软雅黑),第二个是大小,第三个是加粗(权重是75)
m_pLabel->setStyleSheet("color:white;");
m_pLabel->setFont(font);
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->addWidget(m_pLabel, Qt::AlignCenter);
this->setLayout(vlayout);
}
copy and paste