不规则窗口,透明半透明窗口
设置窗口属性
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
绘制带alpha通道的图片
// paintEvent()函数中
QPainter painter(this);
QImage bg("background.png");
painter.drawImage(0, 0, bg);
窗口剪裁区域
将绘制限制在剪裁区域中,设置一个圆角矩形的剪裁区域
// paintEvent()函数中
QPainter painter(this);
painter.setClipping(true);
QPainterPath clipPath;
clipPath.addRoundedRect(0, 0, width(), height(), 50, 50);
painter.setClipPath(clipPath);
圆角矩形窗口
设置窗口属性
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
绘制圆角矩形
如果什么都不绘制,整个窗口都是透明的,即绘制什么就显示什么,另外alpha通道会影响半透明值
// paintEvent()函数中
QPainter painter(this);
painter.setClipping(true);
QPainterPath roundRect;
roundRect.addRoundedRect(0, 0, width(), height(), 50, 50);
painter.fillPath(roundRect, QBrush(QColor(100, 100, 100)));
待续…
参考
QT 求助怎么 实现圆角窗口的……
http://www.qtcn.org/bbs/read.php?tid=34559
QT实现窗口透明的方法
http://blog.youkuaiyun.com/liuwumiyuhuiping/article/details/6955692