QT创建透明窗体

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

 void Widget::resizeEvent(QResizeEvent *)
 {
     // Use a bitmap as a mask. A bitmap only has two kind of colors: white(value is 0)
         // or black(other values). When we use it to set mask, we can see the window at the position
         // where the color value is 0, and other place will be transparent.
         QBitmap bitMap(width(),height()); // A bit map has the same size with current widget
         QPainter painter(&bitMap);
         painter.setPen(QColor(255,255,255)); // Any color that is not QRgb(0,0,0) is right
         painter.drawRect(0,0,width(),height());
         // Now begin to draw the place where we want to show it
         painter.setPen(QColor(0,0,0));
         painter.drawText( (width()-300)/2,0,300,50,Qt::AlignHCenter," 1");
         setMask(bitMap);
 }

Widget::~Widget()
{
    delete ui;
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaodong60606/article/details/49943947
个人分类: QT
上一篇ubuntu 配置php
下一篇linux程序通过消息队列传输数据
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭