简体   繁体   English

QT中的透明小部件

[英]transparent widget in QT

I want to draw a circle on a widget and within the circle background screen should be visible ie just border/circumference of circle should be visible on the widget. 我想在小部件上绘制一个圆,并且在圆背景屏幕内应该可见,即,在小部件上应该仅可见圆的边界/圆周。 Rest of the widget should be transparent. 小部件的其余部分应该是透明的。 I have tried : 1) setStyleSheet("background:transparent;") 2) setAttribute( Qt::WA_TranslucentBackground, true ); 我已经尝试过:1) setStyleSheet("background:transparent;") 2) setAttribute( Qt::WA_TranslucentBackground, true ); 3) Overriding paintEvent(QPaintEvent* event); 3) Overriding paintEvent(QPaintEvent* event);

All of the above methode didn't work. 以上所有方法均无效。 and setAutoFillBackground() is false. 并且setAutoFillBackground()为false。 I am new to Qt and above solution I just found on google. 我是刚接触Google的Qt和以上解决方案的新手。 Please Help. 请帮忙。

This will do the job :D 这将完成工作:D

#include <QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QMainWindow *win=new QMainWindow(0);
    win->setAttribute(Qt::WA_TranslucentBackground,true);
    win->show();
    return a.exec();
}

The QWidget::setMask function, if used on the window, will have that affect. 如果在窗口上使用QWidget::setMask函数,则会产生这种影响。 See also the shaped clock example (also referenced from the setMask documentation). 另请参见整形时钟示例 (也可从setMask文档中引用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM