# QT创建透明窗体

176人阅读 评论(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");
}

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

0
0

个人资料
• 访问：40121次
• 积分：1149
• 等级：
• 排名：千里之外
• 原创：74篇
• 转载：27篇
• 译文：0篇
• 评论：2条
文章分类
最新评论