-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsliderctrl.py
More file actions
59 lines (43 loc) · 1.79 KB
/
sliderctrl.py
File metadata and controls
59 lines (43 loc) · 1.79 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from PySide6.QtWidgets import (
QApplication, QWidget, QHBoxLayout, QGroupBox, QSlider, QLabel
)
from PySide6.QtCore import Qt, Signal
class SliderControlInt(QWidget):
# Custom signal to notify parent of value change
value_changed = Signal(int)
def __init__(self, title: str, def_value: int, min_value: int, max_value: int, parent=None):
super().__init__(parent)
self.group_box = QGroupBox(title)
self.slider = QSlider(Qt.Horizontal)
self.label = QLabel()
self.slider.setRange(min_value, max_value)
self.slider.setValue(def_value)
self.label.setText(f"{def_value:3}")
self.slider.valueChanged.connect(self._on_slider_value_changed)
group_layout = QHBoxLayout()
group_layout.addWidget(self.slider)
group_layout.addWidget(self.label)
self.group_box.setLayout(group_layout)
main_layout = QHBoxLayout(self)
main_layout.addWidget(self.group_box)
self.setLayout(main_layout)
def _on_slider_value_changed(self, value: int):
self.label.setText(f"{value:3}")
self.value_changed.emit(value)
# Example usage
# if __name__ == "__main__":
# import sys
# class TestWindow(QWidget):
# def __init__(self):
# super().__init__()
# self.setWindowTitle("Slider Control Test")
# self.slider_control = SliderControlInt("My Slider", 0, 180)
# self.slider_control.value_changed.connect(self.on_slider_changed)
# layout = QVBoxLayout(self)
# layout.addWidget(self.slider_control)
# def on_slider_changed(self, value: int):
# print(f"Parent received value: {value}")
# app = QApplication(sys.argv)
# window = TestWindow()
# window.show()
# sys.exit(app.exec())