关闭

QT创建透明窗体

136人阅读 评论(0) 收藏 举报
分类:
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;
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:33993次
    • 积分:1094
    • 等级:
    • 排名:千里之外
    • 原创:74篇
    • 转载:27篇
    • 译文:0篇
    • 评论:2条
    文章分类
    最新评论