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;
}
QT创建透明窗体
最新推荐文章于 2020-02-12 00:36:37 发布