-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog_slider.py
45 lines (38 loc) · 1.63 KB
/
dialog_slider.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
39
40
41
42
43
44
45
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ====================================================================
# @author: Joe Del Rocco
# @since: 10/10/2018
# @summary: Dialog for getting a value from the user with a slider.
# ====================================================================
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
class DialogSlider(QDialog):
def __init__(self, parent, title, message, value, min, max, step, winflags=Qt.WindowSystemMenuHint | Qt.WindowTitleHint):
super().__init__(parent, winflags | Qt.WindowCloseButtonHint | Qt.Window)
# window
self.setWindowTitle(title)
self.setWindowIcon(QIcon('res/icon.png'))
# layout
layout = QVBoxLayout()
layout.setSpacing(5)
layout.setContentsMargins(10, 10, 10, 10)
label = QLabel(message)
layout.addWidget(label)
self.slider = QSlider(Qt.Horizontal, self)
self.slider.setTickPosition(QSlider.TicksAbove)
self.slider.setRange(min, max)
self.slider.setValue(value)
self.slider.setTickInterval(step)
self.slider.setPageStep(step)
layout.addWidget(self.slider)
# accept/decline buttons
boxButtons = QDialogButtonBox()
btn = boxButtons.addButton("OK", QDialogButtonBox.AcceptRole)
btn.clicked.connect(self.accept)
btn = boxButtons.addButton("Cancel", QDialogButtonBox.RejectRole)
btn.clicked.connect(self.reject)
layout.addWidget(boxButtons, 0, Qt.AlignBottom)
self.setLayout(layout)
layout.setSizeConstraint(QLayout.SetFixedSize)