2 Star 0 Fork 1

chen227 / clock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
widget.cpp 2.37 KB
一键复制 编辑 原始数据 按行查看 历史
chen227 提交于 2018-03-27 11:00 . first commit
#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();
}
1
https://gitee.com/chen227/clock.git
git@gitee.com:chen227/clock.git
chen227
clock
clock
master

搜索帮助