我那么做了,但是透明的区域显示的是黑色,网上查资料说是如果父对象为空的话会出现这种情况
下面是我的代码,请问下大神该怎么修改? 其实应该说父对象就是对话框它本身吧,怎么样才能解决透明区域是黑块的问题?
#include <QtGui>
#include "loginDialog.h"
loginDialog::loginDialog(QWidget *parent)
: QDialog(parent, Qt::FramelessWindowHint)
{
usernameLabel = new QLabel(tr("用户名"));
passwordLabel = new QLabel(tr("密码));
usernameEdit = new QLineEdit;
passwordEdit = new QLineEdit;
loginButton = new QPushButton(tr("登录"));
setAttribute(Qt::WA_TranslucentBackground, true);
background.load(":/images/background.png");
setFixedSize(370, 266);
layout = new QHBoxLayout;
layout->addWidget(usernameLabel);
layout->addWidget(usernameEdit);
setLayout(layout);
}
void loginDialog::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap(0, 0, 380, 276, background);
}