首页| 论坛| 消息

标题:自定义标题栏在调用时设置背景色无效
作者:longhai915
日期:2016-11-18 14:12
内容:

本人菜鸟一枚,正在学习QT。目前正在学习设计自定义标题栏,我希望通过代码设置自定标题栏的背景色,但是无效,请大家帮帮忙,看看怎么回事。
自定义的CustomWidget类,构造函数如下:CustomWidget::CustomWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CustomWidget)
{
//设置无边框
setWindowFlags(Qt::FramelessWindowHint);
//设置透明效果
//setAttribute(Qt::WA_TranslucentBackground);
setWindowOpacity(1);
ui->setupUi(this);

m_bPlayCloseAnimation = true;
closeAnimationState = notplay;
QPalette pal(palette());
pal.setColor(QPalette::Background, QColor(200, 200, 200, 255));
setAutoFillBackground(true);
setPalette(pal);

TitleBar *pTitleBar = new TitleBar(this);
pTitleBar->setDefault();
//installEventFilter必须在setWindowTitle、setWindowIcon之前调用,
//因为必须先安装事件过滤器,相应事件触发时,才会进入标题栏的eventFilter事件中
installEventFilter(pTitleBar);
setWindowTitle(tr("Custom Window"));
//setWindowIcon(QIcon(":/Images/logo.png"));

QVBoxLayout *pLayout = new QVBoxLayout(this);
pLayout->addWidget(pTitleBar);
pLayout->addStretch();
pLayout->setSpacing(0);
pLayout->setContentsMargins(0, 0, 0, 0);
setLayout(pLayout);
}[col ..


#1 [longhai915 11-19 12:26]
哈哈已经结果了

回复 发表
主题 版块