程序运行截图如下:

关键点一:

->:这个箭头表示左边的类是放到右边的类里面的

QWidget->QGraphicsProxyWidget

QGraphicsProxyWidget->QGraphicsScene

QGraphicsScene->QGraphicsView

本程序中在Ui中QGraphicsView是放入在QWIdget中的

关于QGraphicsProxyWidget的笔记请看:

https://blog.csdn.net/qq78442761/article/details/81507130

关键点二:

QTimeLine是Qt的时间线函数,线有两端,所以有2个方向,一般都使用QTimeLine实现这种生动的旋转。

源码如下:

mycustomproxy.h

#ifndef MYCUSTOMPROXY_H
#define MYCUSTOMPROXY_H#include <QGraphicsProxyWidget>
#include <QTimeLine>QT_BEGIN_NAMESPACE
class QGraphicsSceneHoverEvent;
QT_END_NAMESPACEclass MyCustomProxy : public QGraphicsProxyWidget
{Q_OBJECT
public:explicit MyCustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);~MyCustomProxy();protected:void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;protected slots:void updateStep(int step);void finished();private:QTimeLine *m_timeLine;qreal m_currAngle;
};#endif // MYCUSTOMPROXY_H

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>QT_BEGIN_NAMESPACE
class QGraphicsScene;
QT_END_NAMESPACEnamespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = 0);~Widget();private:Ui::Widget *ui;QGraphicsScene *m_scene;
};#endif // WIDGET_H

widgetwindow.h

#ifndef WIDGETWINDOW_H
#define WIDGETWINDOW_H#include <QWidget>namespace Ui {
class WidgetWindow;
}class WidgetWindow : public QWidget
{Q_OBJECTpublic:explicit WidgetWindow(QWidget *parent = 0);~WidgetWindow();protected slots:void btnClicked();private:Ui::WidgetWindow *ui;
};#endif // WIDGETWINDOW_H

main.cpp

#include "widget.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();return a.exec();
}

mycustomproxy.cpp

#include "mycustomproxy.h"
#include <QDebug>
#include <QGraphicsScene>
#include <QTransform>MyCustomProxy::MyCustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags): QGraphicsProxyWidget(parent,wFlags)
{QTransform transform;setTransform(transform.rotate(-60,Qt::YAxis));m_currAngle=0;m_timeLine=new QTimeLine;m_timeLine->setFrameRange(-60,0);connect(m_timeLine,SIGNAL(frameChanged(int)),this,SLOT(updateStep(int)));connect(m_timeLine,SIGNAL(finished()),this,SLOT(finished()));
}MyCustomProxy::~MyCustomProxy()
{}void MyCustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{scene()->setActiveWindow(this);m_timeLine->setDirection(QTimeLine::Forward);if(m_timeLine->state()!=QTimeLine::Running)m_timeLine->start();QGraphicsProxyWidget::hoverEnterEvent(event);
}void MyCustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{m_timeLine->setDirection(QTimeLine::Backward);if(m_timeLine->state()!=QTimeLine::Running)m_timeLine->start();QGraphicsProxyWidget::hoverLeaveEvent(event);
}void MyCustomProxy::updateStep(int step)
{//qDebug()<<"step:"<<step;QTransform transform;setTransform(transform.rotate(step,Qt::YAxis));
}void MyCustomProxy::finished()
{//qDebug()<<"finished!";
}

widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include "widgetwindow.h"
#include "mycustomproxy.h"
#include <QGraphicsScene>
#include <QDebug>
#include <QTransform>Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);ui->graphicsView->setStyleSheet("background: transparent;border:0px");ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);ui->graphicsView->setRenderHints(ui->graphicsView->renderHints()|QPainter::Antialiasing|QPainter::SmoothPixmapTransform);setWindowFlags(Qt::Window|Qt::FramelessWindowHint);setAttribute(Qt::WA_TranslucentBackground);m_scene=new QGraphicsScene;ui->graphicsView->setScene(m_scene);MyCustomProxy *myCustomProxy_1=new MyCustomProxy;myCustomProxy_1->setWidget(new WidgetWindow);myCustomProxy_1->setWindowFlags(Qt::Desktop);myCustomProxy_1->setWindowTitle("QWidget demo 中文");myCustomProxy_1->setPos(-300,0);MyCustomProxy *myCustomProxy_2=new MyCustomProxy;myCustomProxy_2->setWidget(new WidgetWindow);myCustomProxy_2->setWindowFlags(Qt::Desktop);myCustomProxy_2->setWindowTitle("QWidget demo 中文");myCustomProxy_2->setPos(-150,0);MyCustomProxy *myCustomProxy_3=new MyCustomProxy;myCustomProxy_3->setWidget(new WidgetWindow);myCustomProxy_3->setWindowFlags(Qt::Desktop);myCustomProxy_3->setWindowTitle("QWidget demo 中文");myCustomProxy_3->setPos(0,0);MyCustomProxy *myCustomProxy_4=new MyCustomProxy;myCustomProxy_4->setWidget(new WidgetWindow);myCustomProxy_4->setWindowFlags(Qt::Desktop);myCustomProxy_4->setWindowTitle("QWidget demo 中文");myCustomProxy_4->setPos(150,0);MyCustomProxy *myCustomProxy_5=new MyCustomProxy;myCustomProxy_5->setWidget(new WidgetWindow);myCustomProxy_5->setWindowFlags(Qt::Desktop);myCustomProxy_5->setWindowTitle("QWidget demo 中文");myCustomProxy_5->setPos(300,0);m_scene->addItem(myCustomProxy_1);m_scene->addItem(myCustomProxy_2);m_scene->addItem(myCustomProxy_3);m_scene->addItem(myCustomProxy_4);m_scene->addItem(myCustomProxy_5);ui->graphicsView->setSceneRect(-404.027,-40.2044,939.058,402.725);ui->graphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
}Widget::~Widget()
{delete ui;
}

widgetwindow.cpp

#include "widgetwindow.h"
#include "ui_widgetwindow.h"
#include <QMessageBox>WidgetWindow::WidgetWindow(QWidget *parent) :QWidget(parent),ui(new Ui::WidgetWindow)
{ui->setupUi(this);connect(ui->pushButton,SIGNAL(clicked(bool)),this,SLOT(btnClicked()));
}WidgetWindow::~WidgetWindow()
{delete ui;
}void WidgetWindow::btnClicked()
{QMessageBox::information(this,"提示","按钮被按下了!");
}

Qt工作笔记-3D效果唤出QWidgets界面(QGraphicsProxyWidget与QTimeLine)相关推荐

  1. Qt Creator应用3D效果

    Qt Creator应用3D效果 应用3D效果 可用效果 应用3D效果 Qt Design Studio提供了一组Qt Quick 3D效果,这些效果继承了Qt Quick 3D Effects模块中 ...

  2. Qt工作笔记-发送端发送Json格式的数据包,接收端解析数据包

    原理以及运行 原理是因为QJsonDocument提供了一个函数toJson 可以直接把Json数据转成QByteArray,这样就可以直接发送数据包,然后再按照常规方法解析即可,本源码中含解析内容, ...

  3. Qt工作笔记-QML界面与QWidgets界面相互交互

    C++要做的事情: 1.QML中注册C++类型(qmlRegisterType) 2.获取元对象树,从中提取注册的指针[这样就和普通的对象一样了] qml要做的事情: 1.import注册的C++类型 ...

  4. Qt工作笔记-Windows上界面滑动效果

    运行截图如下: 源码如下: widget.h #ifndef WIDGET_H #define WIDGET_H#include <QWidget>QT_BEGIN_NAMESPACE c ...

  5. Qt工作笔记-html做界面时,QFileInfo小技巧,获取前端页面

    目录 背景 演示及代码 总结 背景 有的时候要调用三方的库,能够比较简单的实现一些酷炫的效果.这里特别是前端的酷炫效果! 如果在Qt中,某个地方,能小范围使用前端Qt的效果,辣么,将会是一个多么有意思 ...

  6. Qt文档阅读笔记|Qt工作笔记-setupUi官方解析与实例(widgets中界面与业务分离)

    目录 前言 官方解析 模拟界面与业务分离过程 博主栗子 前言 在最开始创建Qt项目的时候,已经默认添加好了,现在来分析下,这么做有什么意义! 官方解析 void QWidget::setupUi(QW ...

  7. Qt工作笔记-通过C++使widgets与QQuick交互(包含qml界面对象与C++对象映射)

    目录 理论及程序运行 源码 理论及程序运行 这里要注意,通过qmlRegisterType函数去注册一个QML类! 下面再指明一个关键的问题,如何把QML界面的对象映射到C++呢! 可以有如下的处理: ...

  8. Qt工作笔记-使用信号与槽让两个界面进行数据通信

    今天在项目中,发现有一个十分重要的功能,就是2个界面进行数据通信. 记得1年多前,刚刚学习Qt,对这个无法理解,然后经过一年多的学习和理解,在此把自己学习的感悟和知识在此总结下. 下面是使用emit ...

  9. Qt工作笔记-让界面飞一会(让界面旋转出来)

    程序运行截图如下: 原理:在Widget上面套一个QGraphicsView,把Widget放入QGraphicsProxyWidget,然后对QGraphicsProxyWidget操作即可! 源码 ...

最新文章

  1. [导入]看图说话,编写VS2005插件,增强VS2005 IDE
  2. node.js入门系列(一)--Node.js简介
  3. memcached企业面试题
  4. python 几何_OpenCV-Python系列之对极几何理论
  5. mac 安装nvm和nvm常见的命令
  6. aspnetcore 实现简单的伪静态化
  7. JS面向对象编程实现
  8. MyBatis启动流程分析
  9. java 动态获取IP地址(城市)
  10. webpack多页面开发与懒加载hash解决方案
  11. excel不显示0_【扫盲】小白必看:excel表里数字格式常见的几种错误?
  12. 嵌入式linux ucgui,四、嵌入式之图形界面 (3) uCGui
  13. dcdc转换器计算机显示,DC/DC转换器
  14. 「Windows Bug」Window 系统下双网卡内外网冲突
  15. 如何做接口测试呢?接口测试有哪些工具【小白都会系列】
  16. SpringBoot(53) 整合canal实现数据同步
  17. er2100虚拟服务器,华三er2100n路由器恢复出厂设置
  18. 二十七、74LS148芯片解析
  19. 密码学的骰子——随机数
  20. 源码编译安装go,ERROR: Cannot find /root/go1.4/bin/go

热门文章

  1. 起到的C++是中间层的作用
  2. 飞鸽传书渐成政务办公工具
  3. 大白话,讲编程之《ES6系列连载》汇总,再也不用翻历史消息了
  4. html制作花样链接卡页面_8 个「新标签页」Chrome 扩展,把 New Tab 页面玩出花样 | Matrix 精选...
  5. opengl实现经纹理映射的旋转立方体_《图形编程技术学习》(五十三)环境映射...
  6. 嵌入式开发板01---点亮LED
  7. C++重载函数和重载运算符
  8. 监督学习 | 朴素贝叶斯原理及Python实现
  9. Opencv 图像入门一之基本操作
  10. AnimalTFDB 3.0 | 动物转录因子注释和预测的综合资源库