zoukankan      html  css  js  c++  java
  • 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.setFixedSize(QSize(800, 400));
    12     w.show();
    13     return  a.exec();
    14 }
    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 
    11 class  Dialog :  public  QWidget
    12 {
    13  Q_OBJECT
    14 public :
    15  Dialog(QWidget *parent = 0);
    16  ~Dialog();
    17 
    18   virtual void paintEvent(QPaintEvent *event);
    19 };
    20 
    21 
    22 #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     le->setGeometry(300, 150, 100, 30);
     9 
    10     this->setAttribute(Qt::WA_TranslucentBackground, true);
    11 }
    12 
    13 Dialog::~Dialog()
    14 {
    15 }
    16 
    17 void Dialog::paintEvent(QPaintEvent *event)
    18 {
    19     QBitmap bitMap(width( ), height( ));
    20     //创建一个跟窗口一样的bitMap
    21     QPainter bitMapPainter(&bitMap);
    22     bitMapPainter.setPen(Qt::GlobalColor::color0);
    23     //先填充
    24     bitMapPainter.drawRect(0, 0, width( ), height( ));
    25     //下面换成你自己的图片。
    26     QPixmap imageTest(":/new/prefix1/1408266602_762236.png");
    27     //然后bitMap就有了你的图片。
    28     bitMapPainter.drawPixmap(0, 0, imageTest.width( ), imageTest.height( ), imageTest);
    29     setMask(bitMap);
    30 }
    View Code
  • 相关阅读:
    触发器实现从TagBlinkLogs往历史表TagLocationHis20125插入一条数据,实现的是在不同的条件下改变相应的状态
    v$sql,V$SQLTExT和v$sqlarea区别与联系
    centos 下增加swap空间大小
    【转载】telnet: connect to address 127.0.0.1: Connection refused
    【原】centos系统命令部分不可用
    [转]linux下的ssh配置
    [原]linux 配置 ssh 等效性
    ORA03113: endoffile on communication channel Process ID: 252 Session ID: 1 Serial number: 3
    【转载】使用rlwrap增强Linux中的sqlplus命令行功能
    [转]详细解说:简单CSS3实现炫酷读者墙
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/14150385.html
Copyright © 2011-2022 走看看