-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_button.py
38 lines (34 loc) · 1.4 KB
/
settings_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
# Settings Button is hidden behind welcome message
# Settings can be reached by long pressig (https://stackoverflow.com/a/13851527) the text in the label
from PyQt5 import QtWidgets, QtCore
class SettingsButton(QtWidgets.QPushButton):
longclicked = QtCore.pyqtSignal(bool)
def __init__(self, *args, **kwargs):
QtWidgets.QPushButton.__init__(self, *args, **kwargs)
self.setAutoRepeat(True)
self.setAutoRepeatInterval(1000)
self.clicked.connect(self.handleClicked)
self.long_press_duration = 5000
self.setFlat(True)
self.setStyleSheet("QPushButton { background-color: transparent; border: 0px}");
self.setMinimumSize(2000, 2000)
def handleClicked(self):
#print(self.long_press_duration)
if self.isDown():
if self.long_press_duration > 0:
self.long_press_duration -= 50
self.setAutoRepeatInterval(50)
else:
print('Button long pressed')
self.long_press_duration = 5000
self.setAutoRepeatInterval(1000)
self.longclicked.emit(True)
else:
self.long_press_duration = 5000
self.setAutoRepeatInterval(1000)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
button = SettingsButton('Press and Hold to reach settings')
button.show()
sys.exit(app.exec_())