Qt-透明窗体之半透明

 相关资料:

https://download.csdn.net/download/zhujianqiangqq/13713144    代码包下载

 

.pro

复制代码
 1 QT       += core gui
 2 
 3 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 4 
 5 CONFIG += c++11
 6 
 7 # The following define makes your compiler emit warnings if you use
 8 # any Qt feature that has been marked deprecated (the exact warnings
 9 # depend on your compiler). Please consult the documentation of the
10 # deprecated API in order to know how to port your code away from it.
11 DEFINES += QT_DEPRECATED_WARNINGS
12 
13 # You can also make your code fail to compile if it uses deprecated APIs.
14 # In order to do so, uncomment the following line.
15 # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
17 
18 SOURCES += \
19     main.cpp \
20     windowDesktop.cpp
21 
22 HEADERS += \
23     windowDesktop.h
24 
25 FORMS += \
26     mainwindow.ui
27 
28 LIBS += -lUser32
29 
30 # Default rules for deployment.
31 qnx: target.path = /tmp/$${TARGET}/bin
32 else: unix:!android: target.path = /opt/$${TARGET}/bin
33 !isEmpty(target.path): INSTALLS += target
34 
35 RESOURCES += \
36     resource.qrc
View Code
复制代码

main.cpp

复制代码
 1 #include <windows.h>
 2 #include <winuser.h>
 3 #include <QApplication>
 4 #include "windowDesktop.h"
 5 
 6 int main(int argc, char *argv[])
 7 {
 8     QApplication a(argc, argv);
 9 
10     Dialog w;
11     w.setWindowFlag(Qt::FramelessWindowHint);
12     w.setFixedSize(QSize(800, 400));
13     w.show();
14     return  a.exec();
15 }
View Code
复制代码

windowDesktop.h

复制代码
 1 #ifndef WINDOWDESKTOP_H
 2 #define WINDOWDESKTOP_H
 3 
 4 #include "QObject"
 5 #include "QDialog"
 6 #include "QLineEdit"
 7 #include "QPainter"
 8 #include "QWidget"
 9 #include "QBitmap"
10 #include "QPushButton"
11 
12 class  Dialog :  public  QWidget
13 {
14  Q_OBJECT
15 public :
16  Dialog(QWidget *parent = 0);
17  ~Dialog();
18 
19   virtual void paintEvent(QPaintEvent *event);
20 };
21 
22 
23 #endif // WINDOWDESKTOP_H
View Code
复制代码

windowDesktop.cpp

复制代码
 1 #include "windowDesktop.h"
 2 
 3 Dialog::Dialog(QWidget *parent)
 4     : QWidget(parent)
 5 {    
 6     // 创建个LineEdit用来测试焦点
 7     QLineEdit *le = new QLineEdit(this);
 8     QPushButton *oButton = new QPushButton(this);
 9     oButton->setText("test");
10     oButton->setGeometry(30, 30, 100, 30);
11 
12     this->setAttribute(Qt::WA_TranslucentBackground, true);
13 }
14 
15 Dialog::~Dialog()
16 {
17 }
18 
19 void Dialog::paintEvent(QPaintEvent *event)
20 {
21     QPainter p(this);
22     p.fillRect(rect(), QColor(0, 0xff, 0, 33));
23     return;
24 }
View Code
复制代码

 

posted on   疯狂delphi  阅读(154)  评论(0编辑  收藏  举报

编辑推荐:
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
阅读排行:
· dotnet 源代码生成器分析器入门
· 官方的 MCP C# SDK:csharp-sdk
· 一款 .NET 开源、功能强大的远程连接管理工具,支持 RDP、VNC、SSH 等多种主流协议!
· 一步一步教你部署ktransformers,大内存单显卡用上Deepseek-R1
· 一次Java后端服务间歇性响应慢的问题排查记录
历史上的今天:
2015-12-17 Delphi实例-IdTCPServer和IdTCPClient的使用(支持文件发送)

导航

统计

点击右上角即可分享
微信分享提示