-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_histogram_layout.py
More file actions
83 lines (67 loc) · 3.11 KB
/
test_histogram_layout.py
File metadata and controls
83 lines (67 loc) · 3.11 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from PyQt6.QtWidgets import (
QWidget, QFormLayout, QHBoxLayout, QVBoxLayout,
QDoubleSpinBox, QSpinBox, QToolButton, QComboBox, QApplication
)
from PyQt6.QtCore import Qt
import sys
class HistogramGroupBox(QWidget):
def __init__(self):
super().__init__()
self.setupUI()
def setupUI(self):
self.setObjectName("groupBoxHistogram")
form_layout = QFormLayout(self)
form_layout.setContentsMargins(6, 6, 6, 6)
self.setLayout(form_layout)
# --- Bin width row ---
self.doubleSpinBoxBinWidth = QDoubleSpinBox(parent=self)
self.doubleSpinBoxBinWidth.setMaximum(100000.0)
self.doubleSpinBoxBinWidth.setObjectName("doubleSpinBoxBinWidth")
form_layout.addRow("Bin width", self.doubleSpinBoxBinWidth)
# --- Number of bins row (with Reset button and link button) ---
bin_widget = QWidget(parent=self)
bin_layout = QHBoxLayout(bin_widget)
bin_layout.setContentsMargins(0, 0, 0, 0)
bin_layout.setSpacing(6)
# Vertical layout for spin box + optional other controls stacked
spin_layout = QVBoxLayout()
spin_layout.setContentsMargins(0, 0, 0, 0)
spin_layout.setSpacing(6)
self.spinBoxNBins = QSpinBox(parent=self)
self.spinBoxNBins.setMinimum(1)
self.spinBoxNBins.setMaximum(500)
self.spinBoxNBins.setObjectName("spinBoxNBins")
# Optional Reset button
self.toolButtonHistogramReset = QToolButton(parent=self)
self.toolButtonHistogramReset.setText("Reset")
self.toolButtonHistogramReset.setToolTip("Reset number of bins to default value.")
self.toolButtonHistogramReset.setObjectName("toolButtonHistogramReset")
self.toolButtonHistogramReset.setFixedHeight(self.spinBoxNBins.sizeHint().height())
spin_layout.addWidget(self.spinBoxNBins)
bin_layout.addLayout(spin_layout)
# Add Reset button next to the spin box
bin_layout.addWidget(self.toolButtonHistogramReset, alignment=Qt.AlignmentFlag.AlignVCenter)
# Add link button (centered vertically between the spin box and Reset button if needed)
self.linkButton = QToolButton(parent=bin_widget)
self.linkButton.setCheckable(True)
self.linkButton.setChecked(True)
self.linkButton.setText("🔗")
self.linkButton.setFixedSize(30, 30)
# Use a vertical layout with stretch to center the button
link_layout = QVBoxLayout()
link_layout.setContentsMargins(0, 0, 0, 0)
link_layout.addStretch()
link_layout.addWidget(self.linkButton, alignment=Qt.AlignmentFlag.AlignCenter)
link_layout.addStretch()
bin_layout.addLayout(link_layout)
form_layout.addRow("No. Bins", bin_widget)
# --- Histogram type combo ---
self.comboBoxHistType = QComboBox(parent=self)
self.comboBoxHistType.setObjectName("comboBoxHistType")
form_layout.addRow("Histogram type", self.comboBoxHistType)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = HistogramGroupBox()
w.resize(400, 200)
w.show()
sys.exit(app.exec())