QFrame *frame = new QFrame(this);
ui.setupUi(this);
frame->setStyleSheet("QFrame{background-color: rgb(229, 229, 229);border-radius:5px}"); //设置圆角与背景透明
frame->setGeometry(5, 5, this->width() - 10, this->height() - 10);//设置有效范围框
QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);
shadow_effect->setOffset(0, 0);
shadow_effect->setColor(Qt::black);
shadow_effect->setBlurRadius(10);
frame->setGraphicsEffect(shadow_effect);
...
this->setStyleSheet("QWidget{border-radius:0px}"); //设置圆角与背景透明
this->setAttribute(Qt::WA_TranslucentBackground);//特别注意这句 //如果发现没有效果,那可能你设置了底层布局的问题。因为你可能设置了底层布局setContentsMargins的关系,如是,调整这个函数的参数即可
//this->setWindowFlags(Qt::FramelessWindowHint);
this->setMouseTracking(true);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
当然这个不是最好的办法。重写printEvent可能最好用