Bonjour,
J'ai ce widget :
Le but est d'avoir côte à côte 2 valeurs non modifiables et une valeur ajustable.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 class MaintenanceItemWidget(QWidget): """This is line in the MaintenanceWidget. It display 3 values: partial, global and threshold. Threshold can be adjusted by the user. """ def __init__(self, parent=None): super().__init__(parent) # Widgets self._partial = QLabel() self._global = QLabel() self._threshold = QSpinBox() self._threshold.setMaximum(65535) # 16 bits # Layout layout = QHBoxLayout() layout.addWidget(self._partial) layout.addWidget(self._global) layout.addWidget(self._threshold) self.setLayout(layout) self.set_partial(0) self.set_global(0) def set_partial(self, value): self._partial.setText(str(value)) def set_global(self, value): self._global.setText(str(value))
Je regroupe ensuite plusieurs widgets comme celui dans un autre widget :
Le rendu est celui-ci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 class MaintenanceWidget(QWidget): """Widget to display information about maintenance. It displays partial counters, global counters and thresholds for forward, reverse, operating time and drops. Thresholds can be adjusted by the user. """ def __init__(self, parent=None): super().__init__(parent) # Header header = QHBoxLayout() header.addWidget(QLabel('Partial')) header.addWidget(QLabel('Global')) header.addWidget(QLabel('Threshold')) # Content self._forward = MaintenanceItemWidget() self._reverse = MaintenanceItemWidget() self._operating_time = MaintenanceItemWidget() self._drops = MaintenanceItemWidget() # Layout layout = QFormLayout() layout.addRow('', header) layout.addRow('Forward', self._forward) layout.addRow('Reverse', self._reverse) layout.addRow('Operating time', self._operating_time) layout.addRow('Drops', self._drops) self.setLayout(layout)
J'aurais aimé que chaque widget d'une ligne occupe la même place que ses voisins, et non que les QSpinBoxes prennent toute la place.
Une astuce à proposer ? Merci d'avance !
PS : j'espère que les extraits de code sont suffisant et qu'il ne manque rien d'important pour la compréhension.
Partager