You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

#ifndef FLYME_H
#define FLYME_H
#include <QApplication>
#include <QMainWindow>
#include <QMenu>
#include <QContextMenuEvent>
#include <QPoint>
#include <QPushButton>
#include <QIcon>
class FloatingButton : public QPushButton
{
Q_OBJECT
public:
FloatingButton(QWidget *parent = nullptr)
: QPushButton(parent)
{
// 设置悬浮球按钮的大小和位置
setGeometry(QRect(0, 0, 50, 50));
setIcon(QIcon(":/images/ball.png"));
setIconSize(QSize(50, 50));
// 设置不透明度
setWindowOpacity(0.8);
// 隐藏边框
setFlat(true);
// 设置窗口标志为窗口置顶
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
}
protected:
void contextMenuEvent(QContextMenuEvent *event) override
{
// 创建一个右键菜单
QMenu menu(this);
menu.addAction("选项一");
menu.addAction("选项二");
menu.addAction("选项三");
// 将右键菜单移动到鼠标单击的位置
menu.exec(event->globalPos());
}
};
#endif // FLYME_H