代码拉取完成,页面将自动刷新
#include "widget.h"
#include "ui_widget.h"
#include <QQuickWidget>
#include <QPixmap>
#include <QPalette>
#include <QColor>
#include <QQmlEngine>
#include <QQmlContext>
#include <QDate>
#include <QSettings>
#include <QDir>
#include <QTextStream>
#include <QDesktopWidget>
#include <QApplication>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
//==================================================================================
this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::SubWindow | Qt::WindowStaysOnTopHint);//窗口置顶,无边框
this->setAttribute(Qt::WA_TranslucentBackground);
this->setAutoFillBackground(true);//填充背景
//================================================================================
QPalette palette;
QPixmap pixmap(":/image/toumingBg.png");
palette.setBrush(QPalette::Window,QBrush(pixmap));//设置笔刷为背景图片
this->setPalette(palette);
this->setFixedSize(228,229);
this->move(getDesktopWidth()-228,0);
//================================================================================
ui->quickWidget->setClearColor(QColor(Qt::transparent)); //qml 透明
ui->quickWidget->engine()->rootContext()->setContextProperty("widget",this);
ui->quickWidget->setSource(QUrl("qrc:/main.qml"));
setSystemMenu();
}
Widget::~Widget()
{
delete ui;
}
int Widget::getDesktopWidth()
{
return QApplication::desktop()->width();
}
int Widget::getDesktopHeight()
{
return QApplication::desktop()->height();
}
void Widget::mousePressEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton){
offset = event->globalPos() - pos();
}
}
void Widget::mouseMoveEvent(QMouseEvent *event)
{
if(event->buttons()&Qt::LeftButton){
QPoint temp;
temp = event->globalPos() - offset;
move(temp);
}
}
void Widget::mouseReleaseEvent(QMouseEvent *event)
{
}
//添加系统托盘
void Widget::setSystemMenu()
{
trayIcon = new QSystemTrayIcon();
trayIcon->setIcon(QIcon(":/exeIcon.ico"));
QMenu *menu = new QMenu();
QAction *action_exit = menu->addAction("退出");
connect(action_exit,SIGNAL(triggered(bool)),this,SLOT(systemExit(bool)));
trayIcon->setContextMenu(menu);
trayIcon->show();
}
void Widget::systemExit(bool b)
{
qApp->quit();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。