-
Notifications
You must be signed in to change notification settings - Fork 4
/
floating_button.py
38 lines (33 loc) · 1.3 KB
/
floating_button.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from PySide6.QtWidgets import QWidget, QVBoxLayout, QPushButton
from PySide6.QtCore import Qt
from PySide6.QtGui import QCursor
class FloatingStopButton(QWidget):
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint | Qt.Tool)
self.setAttribute(Qt.WA_TranslucentBackground)
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
self.stop_button = QPushButton("停止")
self.stop_button.setObjectName("stopButton")
self.stop_button.setStyleSheet("""
QPushButton#stopButton {
background-color: rgba(255, 68, 68, 80%);
color: white;
border: none;
border-radius: 5px;
padding: 5px 15px;
font-size: 13px;
min-height: 25px;
min-width: 60px;
}
QPushButton#stopButton:hover {
background-color: rgba(255, 38, 38, 80%);
}
""")
layout.addWidget(self.stop_button)
self.resize(70, 35)
def show_at_cursor(self):
cursor_pos = QCursor.pos()
self.move(cursor_pos.x() + 20, cursor_pos.y() + 20)
self.show()