首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

Qt纯代码绘制一个等待提示Ui控件-自定义控件

移动开发 4.2KB 50 需要积分: 1
立即下载

资源介绍:

Qt纯代码绘制一个等待提示Ui控件,本示例采用自定义绘图,然后使用Qt动画,达到转圈圈的效果,给大家一个好看的样式示例。你可以根据需要进行修改和扩展,实现你想要的程序启动等待提示栏效果。
#include "waitingspinnerwidget.h" #include #include #include #include WaitingSpinnerWidget::WaitingSpinnerWidget(QWidget *parent, bool centerOnParent, bool disableParentWhenSpinning) : QWidget(parent), _centerOnParent(centerOnParent), _disableParentWhenSpinning(disableParentWhenSpinning) { initialize(); } WaitingSpinnerWidget::WaitingSpinnerWidget(Qt::WindowModality modality, QWidget *parent, bool centerOnParent, bool disableParentWhenSpinning) : QWidget(parent, Qt::Dialog | Qt::FramelessWindowHint), _centerOnParent(centerOnParent), _disableParentWhenSpinning(disableParentWhenSpinning){ initialize(); // We need to set the window modality AFTER we've hidden the // widget for the first time since changing this property while // the widget is visible has no effect. setWindowModality(modality); setAttribute(Qt::WA_TranslucentBackground); } void WaitingSpinnerWidget::initialize() { _color = Qt::black; _roundness = 100.0; _minimumTrailOpacity = 3.14159265358979323846; _trailFadePercentage = 80.0; _revolutionsPerSecond = 1.57079632679489661923; _numberOfLines = 20; _lineLength = 10; _lineWidth = 2; _innerRadius = 10; _currentCounter = 0; _isSpinning = false; _timer = new QTimer(this); connect(_timer, SIGNAL(timeout()), this, SLOT(rotate())); updateSize(); updateTimer(); hide(); } void WaitingSpinnerWidget::paintEvent(QPaintEvent *) { updatePosition(); QPainter painter(this); painter.fillRect(this->rect(), Qt::transparent); painter.setRenderHint(QPainter::Antialiasing, true); if (_currentCounter >= _numberOfLines) { _currentCounter = 0; } painter.setPen(Qt::NoPen); for (int i = 0; i < _numberOfLines; ++i) { painter.save(); painter.translate(_innerRadius + _lineLength, _innerRadius + _lineLength); qreal rotateAngle = static_cast(360 * i) / static_cast(_numberOfLines); painter.rotate(rotateAngle); painter.translate(_innerRadius, 0); int distance = lineCountDistanceFromPrimary(i, _currentCounter, _numberOfLines); QColor color = currentLineColor(distance, _numberOfLines, _trailFadePercentage, _minimumTrailOpacity, _color); painter.setBrush(color); // TODO improve the way rounded rect is painted painter.drawRoundedRect( QRect(0, -_lineWidth / 2, _lineLength, _lineWidth), _roundness, _roundness, Qt::RelativeSize); painter.restore(); } } void WaitingSpinnerWidget::start() { updatePosition(); _isSpinning = true; show(); if(parentWidget() && _disableParentWhenSpinning) { parentWidget()->setEnabled(false); } if (!_timer->isActive()) { _timer->start(); _currentCounter = 0; } } void WaitingSpinnerWidget::stop() { _isSpinning = false; hide(); if(parentWidget() && _disableParentWhenSpinning) { parentWidget()->setEnabled(true); } if (_timer->isActive()) { _timer->stop(); _currentCounter = 0; } } void WaitingSpinnerWidget::setNumberOfLines(int lines) { _numberOfLines = lines; _currentCounter = 0; updateTimer(); } void WaitingSpinnerWidget::setLineLength(int length) { _lineLength = length; updateSize(); } void WaitingSpinnerWidget::setLineWidth(int width) { _lineWidth = width; updateSize(); } void WaitingSpinnerWidget::setInnerRadius(int radius) { _innerRadius = radius; updateSize(); } QColor WaitingSpinnerWidget::color() { return _color; } qreal WaitingSpinnerWidget::roundness() { return _roundness; } qreal WaitingSpinnerWidget::minimumTrailOpacity() { return _minimumTrailOpacity; } qreal WaitingSpinnerWidget::trailFadePercentage() { return _trailFadePercentage; } qreal WaitingSpinnerWidget::revolutionsPersSecond() { return _revolutionsPerSecond; } int WaitingSpinnerWidget::numberOfLines() { return _numberOfLines; } int WaitingSpinnerWidget::lineLength() { return _lineLength; } int WaitingSpinnerWidget::lineWidth() { return _lineWidth; } int WaitingSpinnerWidget::innerRadius() { return _innerRadius; } bool WaitingSpinnerWidget::isSpinning() const { return _isSpinning; } void WaitingSpinnerWidget::setRoundness(qreal roundness) { _roundness = std::max(0.0, std::min(100.0, roundness)); } void WaitingSpinnerWidget::setColor(QColor color) { _color = color; } void WaitingSpinnerWidget::setRevolutionsPerSecond(qreal revolutionsPerSecond) { _revolutionsPerSecond = revolutionsPerSecond; updateTimer(); } void WaitingSpinnerWidget::setTrailFadePercentage(qreal trail) { _trailFadePercentage = trail; } void WaitingSpinnerWidget::setMinimumTrailOpacity(qreal minimumTrailOpacity) { _minimumTrailOpacity = minimumTrailOpacity; } void WaitingSpinnerWidget::rotate() { ++_currentCounter; if (_currentCounter >= _numberOfLines) { _currentCounter = 0; } update(); } void WaitingSpinnerWidget::updateSize() { int size = (_innerRadius + _lineLength) * 2; setFixedSize(size, size); } void WaitingSpinnerWidget::updateTimer() { _timer->setInterval(1000 / (_numberOfLines * _revolutionsPerSecond)); } void WaitingSpinnerWidget::updatePosition() { if (parentWidget() && _centerOnParent) { move(parentWidget()->width() / 2 - width() / 2, parentWidget()->height() / 2 - height() / 2); } } int WaitingSpinnerWidget::lineCountDistanceFromPrimary(int current, int primary, int totalNrOfLines) { int distance = primary - current; if (distance < 0) { distance += totalNrOfLines; } return distance; } QColor WaitingSpinnerWidget::currentLineColor(int countDistance, int totalNrOfLines, qreal trailFadePerc, qreal minOpacity, QColor color) { if (countDistance == 0) { return color; } const qreal minAlphaF = minOpacity / 100.0; int distanceThreshold = static_cast(ceil((totalNrOfLines - 1) * trailFadePerc / 100.0)); if (countDistance > distanceThreshold) { color.setAlphaF(minAlphaF); } else { qreal alphaDiff = color.alphaF() - minAlphaF; qreal gradient = alphaDiff / static_cast(distanceThreshold + 1); qreal resultAlpha = color.alphaF() - gradient * countDistance; // If alpha is out of bounds, clip it. resultAlpha = std::min(1.0, std::max(0.0, resultAlpha)); color.setAlphaF(resultAlpha); } return color; }

资源文件列表:

waitingDemo.zip 大约有5个文件
  1. waitingDemo/
  2. waitingDemo/main.cpp 855B
  3. waitingDemo/waitingDemo.pro 580B
  4. waitingDemo/waitingspinnerwidget.cpp 6.94KB
  5. waitingDemo/waitingspinnerwidget.h 2.38KB
0评论
提交 加载更多评论
其他资源 白日门服务端运维工具,免去运维的对一个个csv文件打开,这里直接打开long目录下的所有文件
白日门服务端运维工具,免去运维的对一个个csv文件打开,这里直接打开long目录下的所有文件
xfsprogs-4.5.0-22.el7离线包
xfsprogs-4.5.0-22.el7离线包
宝塔批量建站工具API批量操作
宝塔批量建站工具API批量操作
Xshell 是一款用于MS Windows平台的强大的SSH、‌telnet和rlogin终端连接仿真软件 ‌
它使得你能轻松和安全地从Windows PC上访问Unix/Linux主机。‌Xshell的主要功能包括SSH和Telnet支持、‌图形用户界面(GUI)、‌会话管理、‌标签页、‌脚本支持、‌文件传输、‌字符集和字体支持以及安全性。‌通过使用SSH协议,‌Xshell提供了数据的加密传输,‌从而增强了连接的安全性。‌Xshell特别适用于系统管理员、‌网络工程师和开发人员等需要经常远程管理主机的用户。‌ Xftp 是一个用于MS Windows平台的强大的FTP和SFTP文件传输程序。‌它能安全地在Unix/Linux和Windows PC之间传输文件。‌Xftp的主要功能是在本地计算机和远程服务器之间提供安全的文件传输服务。‌它支持可视化操作,‌主要用来拷贝文件,‌而Xshell则通过输入命令来对服务器进行操作,‌如启动服务等。‌ 总的来说,‌Xftp和Xshell是两个功能互补的工具,‌它们都可以用于在Windows环境下访问和管理Unix/Linux主机,‌但各有侧重。‌Xftp为可视化工具,‌主要用来拷贝文件,‌而Xshell则通过输入命令来对服务器进行操作,‌如启动服务等
vlc-2673.zip
vlc_2673.zip
vb.net2005+sql2005学生成绩管理软件源码
vb.net2005+sql2005学生成绩管理软件源码
html+css+js隐藏导航栏
html+css+js隐藏导航栏
html+css+js隐藏导航栏 html+css+js隐藏导航栏 html+css+js隐藏导航栏
nginx-rtmp-win32-master.zip
nginx-rtmp-win32-master.zip