资源简介
一个小测试程序,仿制360的悬浮球,难点在于对绘制玄的计算,其他都比较简单,并实现拖动已经鼠标离开后的隐藏,对隐藏时做了细节处理,详细看代码

代码片段和文件信息
#include “fballwidget.h“
#include
#include
#include
#include
#include
#include
#include
#include
FBallWidget::FBallWidget(QWidget *parent)
: QWidget(parent)
m_nMemOcc(20)
{
setWindowFlags(Qt::framelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
setAttribute(Qt::WA_TranslucentBackground);
m_press = false;
m_bg.load(“:/images/background.png“);
QPixmap handle;
handle.load(“:/images/handle.png“);
QPixmap handlePress;
handlePress.load(“:/images/handlePress.png“);
m_handle = new QCursor(handle 0 0);
m_handlePress = new QCursor(handlePress 0 0);
this->setFixedSize(150 62);
setCursor(*m_handle);
int screenWidth = QApplication::desktop()->screenGeometry().width();
int screenHeight = QApplication::desktop()->screenGeometry().height();
this->move(screenWidth - 42 screenHeight * 0.618);
connect(this SIGNAL(notifyExitSoftSig()) this SLOT(OnCloseSlot()));
//动画延迟,否则会有抖动
m_timer = new QTimer(this);
connect(m_timer SIGNAL(timeout()) this SLOT(OnBallHideSlot()));
QTimer* timer = new QTimer(this);
connect(timer SIGNAL(timeout()) this SLOT(OnCountSlot()));
timer->start(500);
}
void FBallWidget::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
m_press = true;
setCursor(*m_handlePress);
}
m_point = event->globalPos() - pos();
}
void FBallWidget::mouseReleaseEvent(QMouseEvent *)
{
setCursor(*m_handle);
m_press = false;
}
void FBallWidget::mouseMoveEvent(QMouseEvent *event)
{
if(m_press)
{
int screenWidth = QApplication::desktop()->screenGeometry().width();
QPoint move_pos = event->globalPos();
QPoint tarPos = move_pos - m_point;
if(tarPos.x() + this->width() > screenWidth)
{
tarPos.setX(screenWidth - this->width());
}
move(tarPos);
}
}
void FBallWidget::mouseDoubleClickEvent(QMouseEvent * event)
{
}
void FBallWidget::enterEvent(QEvent *event)
{
int screenWidth = QApplication::desktop()->screenGeometry().width();
if(this->geometry().x() + this->width() > screenWidth)
{
QRect rect = this->geometry();
rect.setX(screenWidth - this->width());
QPropertyAnimation *pAnimation = new QPropertyAnimation(this “geometry“);
pAnimation->setStartValue(this->geometry());
pAnimation->setEndValue(rect);
pAnimation->setEasingCurve(QEasingCurve::Linear);
pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
isHide = true;
m_over = true;
update();
}
void FBallWidget::leaveEvent(QEvent *event)
{
// int screenWidth = QApplication::desktop()->screenGeometry().width();
// if(this->geometry().x() + this->width()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9944 2018-09-09 16:13 MyFBallDemo\fballwidget.cpp
文件 938 2018-09-09 15:56 MyFBallDemo\fballwidget.h
文件 2798 2017-07-25 20:52 MyFBallDemo\images\background.png
文件 1871 2017-07-25 20:52 MyFBallDemo\images\handle.png
文件 1795 2017-07-25 20:52 MyFBallDemo\images\handlePress.png
文件 240 2018-09-09 11:25 MyFBallDemo\main.cpp
文件 455 2018-09-09 11:11 MyFBallDemo\MyFBallDemo.pro
文件 18577 2018-09-09 11:08 MyFBallDemo\MyFBallDemo.pro.user
文件 190 2018-09-09 11:23 MyFBallDemo\myfballdemo.qrc
文件 201 2018-09-09 11:08 MyFBallDemo\widget.cpp
文件 273 2018-09-09 11:08 MyFBallDemo\widget.h
文件 441 2018-09-09 11:08 MyFBallDemo\widget.ui
目录 0 2018-09-09 11:23 MyFBallDemo\images
目录 0 2018-09-09 16:13 MyFBallDemo
----------- --------- ---------- ----- ----
37723 14
相关资源
- 酒店管理系统基于Qt Creator5)
- vtk QT做的三维地质可视化系统2of2
- Qt局域网聊天软件
- Qt Creator opengl实现四元数鼠标控制轨迹
- QT局域网聊天系统(基于QT5.修改过)
- qt-电子点菜系统
- C 餐厅叫号系统(QT平)
- QT 实现文件下载
- qt图像处理
- QT,JPEG解码源代码(已完成)
- Qt 播放音频文件
- Qt 读取16进制的data文件
- MQTT+串口(usart)透传
- 易语言QQTEA算法源码
- VC工程转Qt工程文件的工具
- MQTT推送Demo
- 基于Linux、QT的视频监控系统的设计与
- Qt 百度地图 定位
- QT酷炫界面开发指南《QmlBook》
- Ubuntu下操作Excel,qt代码
- Qt图片浏览器 --基于Qt的Graphics View f
- qtnribbon2破解
- Qt软件开发 完整项目代码
- MQTT_3.1protocol_Specific中文版
- 在QT中使用RTP进行视频的采集和传输
- Mini6410 Qt4和Qtopia编程开发指南
- Qt实现Code39条形码
- qt_ffmpeg_mp4_export_and_import.zip
- QT5.5入门与项目实战
- Huffman Compress 霍夫曼编码 压缩 解压缩
评论
共有 条评论