在paintEvent中自绘,需要注意的是下面两行代码是必须的。
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
(1)设置窗口属性Qt::WA_TranslucentBackground来设定该窗口半透明显示。
(2)设置Qt::FramelessWindowHint,窗口无边框。如果不设置就会变为下图。
MainWidget w;
w.setAttribute(Qt::WA_TranslucentBackground);
w.setWindowFlags(Qt::FramelessWindowHint);
w.show();
参考:
1.Qt 绘制窗口阴影
2.QT 实现窗口四周阴影