当前位置: 首页 > wzjs >正文

班级博客网站模板网站项目需求分析

班级博客网站模板,网站项目需求分析,广东研发网站建设平台,出口家具东莞网站建设本专栏会不定时更新&#xff0c;如果有有趣的C代码或者编程可以在评论区留言&#xff0c;我会尽量满足粉丝的要求&#xff0c;同时还希望看到的朋友点个赞/收藏&#xff08;感谢/感谢&#xff09; 代码 main.cpp: #include "widget.h"#include <QApplication&g…

本专栏会不定时更新,如果有有趣的C++代码或者编程可以在评论区留言,我会尽量满足粉丝的要求,同时还希望看到的朋友点个赞/收藏(感谢/感谢)

代码

main.cpp:

#include "widget.h"#include <QApplication>
#include<QSystemTrayIcon>
#include<QIcon>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;QSystemTrayIcon sysTray(QIcon("://img/icon.png"),&w);QMenu menu;auto showAct=new QAction("show",&sysTray);auto exitAct=new QAction("exit",&sysTray);QObject::connect(showAct,&QAction::triggered,[&](){w.setVisible(true);});QObject::connect(exitAct,&QAction::triggered,[&](){QApplication::quit();});menu.addAction(showAct);menu.addAction(exitAct);sysTray.setContextMenu(&menu);sysTray.show();w.show();return a.exec();
}

widget.h:

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include<QMap>
#include<QList>
#include<QUrl>
#include<QTimer>
#include<QEvent>
#include<QMouseEvent>
#include<QContextMenuEvent>
#include<QMenu>class QPaintEvent;namespace Act {
Q_NAMESPACEenum RoleAct{Swing,Sleep,SayHello
};
Q_ENUM_NS(RoleAct)}using namespace  Act ;class Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();public:void showActAnimation(RoleAct k);public slots:void onMenuTriggered(QAction* action);protected:void paintEvent(QPaintEvent* event)override;void contextMenuEvent(QContextMenuEvent* event);private:void loadRoleActRes();void initMenu();private:QMap<RoleAct,QList<QUrl>> action_map;QTimer* timer;RoleAct cur_role_act;QUrl cur_role_pix;QMenu* menu;
};class DragFilter:public QObject{public:bool eventFilter(QObject* obj,QEvent* event){auto w=dynamic_cast<QWidget*>(obj);if(!w)return false;if(event->type()==QEvent::MouseButtonPress){auto e=dynamic_cast<QMouseEvent*>(event);if(e){pos=e->pos();}}else if(event->type()==QEvent::MouseMove){auto e=dynamic_cast<QMouseEvent*>(event);if(e){if(e->buttons()&Qt::MouseButton::LeftButton){w->move(e->globalPos()-pos);}}}return QObject::eventFilter(obj,event);}private:QPoint pos;
};#endif // WIDGET_H

widget.cpp

#include "widget.h"
#include<QPaintEvent>
#include<QPainter>//绘图
#include<QPixmap>//图片
#include<QCursor>
#include<QMetaEnum>Widget::Widget(QWidget *parent): QWidget(parent),timer(new QTimer(this)),menu(new QMenu(this))
{this->setWindowFlag(Qt::FramelessWindowHint);//去除窗口边框this->setAttribute(Qt::WA_TranslucentBackground);//背景透明this->installEventFilter(new DragFilter);connect(timer,&QTimer::timeout,[this](){static int index=0;//记录显示动作的当前图片索引auto paths = this->action_map.value(this->cur_role_act);this->cur_role_pix=paths[index++ % paths.size()];//paintEvent() 不允许的this->update();});initMenu();loadRoleActRes();showActAnimation(RoleAct::Swing);
}Widget::~Widget() {}void Widget::showActAnimation(RoleAct k)
{timer->stop();this->cur_role_act=k;timer->start(60);
}void Widget::onMenuTriggered(QAction *action)
{QMetaEnum me=QMetaEnum::fromType<RoleAct>();bool ok;int k =  me.keyToValue(action->text().toStdString().c_str(),&ok);if(!ok)return;showActAnimation(static_cast<RoleAct>(k));
}void Widget::paintEvent(QPaintEvent *event)
{QPainter painter(this);QPixmap pix;pix.load(this->cur_role_pix.toLocalFile());painter.drawPixmap(0,0,pix);}void Widget::contextMenuEvent(QContextMenuEvent *event)
{this->menu->popup(QCursor::pos());
}void Widget::loadRoleActRes()
{auto addRes=[this](RoleAct k,QString path,int count){QList<QUrl> paths;char buf[260];for (int i = 0; i < count; ++i) {memset(buf, 0,sizeof(buf));sprintf_s(buf,path.toStdString().c_str(),i);paths.append(QUrl::fromLocalFile(buf));}action_map.insert(k,paths);};addRes(RoleAct::SayHello,"D:/001/pet/img/sayHello/sayHello_%d.png",28);addRes(RoleAct::Swing,"D:/001/pet/img/swing/swing_%d.png",32);addRes(RoleAct::Sleep,"D:/001/pet/img/sleep/sleep_%d.png",25);
}void Widget::initMenu()
{menu->addAction("SayHello");menu->addAction("Sleep");menu->addAction("Swing");QAction* act=new QAction("Hide");connect(act,&QAction::triggered,[this](){this->setVisible(false);});menu->addAction(act);connect(this->menu,&QMenu::triggered,this,&Widget::onMenuTriggered);
}

演示:

右键会出现四个选项:

点击相应图标会有不同动作。

sleep:

hello:

打包参考文章:Qt程序发布完整教程以及打包成exe文件【小白版】_qt发布可执行程序-CSDN博客

需要代码的可以评论区留言,私聊。

http://www.dtcms.com/wzjs/797981.html

相关文章:

  • 国内互联网建站公司排名越秀网站建设设计
  • wordpress模板 手机版google搜索引擎优化
  • 品牌公司网站设计产品盘网站建设
  • 低价自适应网站建设优化建站贵州建设厅培训中心网站
  • 网站建设需要的服务器ssr网站怎么做
  • 湖南网站建设价格费用大学校园门户网站建设
  • 网站制作2019趋势广西住建领域培训考试系统
  • 昆山有做网站的公司吗万户网络学校网站建设
  • 公司网站建设需要准备哪些资料美食网站建设策划书
  • 网站集约建设电力建设工程质监总站网站
  • 网站制作北京区块链开发公司
  • 微山网站建设哪家便宜wordpress短链识别
  • 电子商务网站建设的结论做网站会什么软件
  • 网站模块wordpress每篇文章怎么加关键词
  • 东莞市建设工程质监督站网站社区cms
  • 虚拟主机网站建设过程企业官网开发公司
  • 洛阳网站建设的公司哪家好郑州网站建设公司电话多少
  • 网站左侧分类菜单怎么做使用模板怎么建站
  • 西数网站管理助手公司网站建设设计如何收费
  • 网站源码带手机版wordpress静态化好处
  • 做印刷哪个网站好宝安seo优化公司
  • 人才招聘网站怎么做开发一个app要多少费用
  • 多种昆明网站建设湛江网站建设技术托管
  • 湖北企业模板建站信息淘宝客 插件 wordpress
  • 企业免费建站怎么做考试资料网站
  • 网站进度条特效2022年域名申请时间
  • 网站结构怎么做临沂网站建设对实体企业的重要性
  • 有人在相亲网站骗人做传销apicloud成品源码
  • 苏州高端网站建设咨询项目计划书ai生成
  • 网站转小程序工具网站开发人员职位晋升空间