1、边框阴影
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(this);
//设置阴影距离
shadow->setOffset(0, 0);
//设置阴影颜色
shadow->setColor(QColor("#444444"));
//设置阴影圆角
shadow->setBlurRadius(10);
//给嵌套QWidget设置阴影
ui->textEdit->setGraphicsEffect(shadow);
2、背景透明,无边框
setWindowFlags(Qt::FramelessWindowHint | Qt::Popup );
setWindowOpacity(1);
setAttribute(Qt::WA_TranslucentBackground, true);
3、在UI添加QTextEdit控件,样式如下
QTextEdit
{
border-radius:10px;border: 2px groove gray;
background-color: rgb(187, 206, 230);
}
4、去除Qt::popup自带阴影
#ifdef Q_OS_WIN32
static bool class_amended = false;
if (event->type() == QEvent::WinIdChange)
{
HWND hwnd = reinterpret_cast<HWND>(winId());
if (class_amended == false)
{
class_amended = true;
DWORD class_style = ::GetClassLong(hwnd, GCL_STYLE);
class_style &= ~CS_DROPSHADOW;
::SetClassLong(hwnd, GCL_STYLE, class_style); // windows系统函数
}
}
#else
//非模态下才能生效
if (event->type() == QEvent::ActivationChange)
{
if(QApplication::activeWindow() != this)
{
this->close();
}
}
#endif
return QDialog::event(event);
5、消息框自适应内容
ui->textEdit->setText(text);
QTextDocument *doc = ui->textEdit->document();
doc->adjustSize(); //这一步不能少
int width = doc->size().toSize().width()+30;
int height = doc->size().toSize().height()+10;
width = width<120 ? 120 : width;
height = height<75 ? 75 : height;
this->setFixedSize(width ,height);
后感:以上参看网上,整理的,感谢分享!!!