Skip to content

Commit c20efc2

Browse files
committed
carbcomn
1 parent b942be5 commit c20efc2

File tree

4 files changed

+64
-12
lines changed

4 files changed

+64
-12
lines changed

src/compas_viewer/components/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .camerasetting import CameraSettingsDialog
55
from .objectsetting import ObjectSettingDialog
66
from .slider import Slider
7+
from .textedit import TextEdit
78
from .treeform import Treeform
89
from .sceneform import Sceneform
910

@@ -14,6 +15,7 @@
1415
"ObjectSettingDialog",
1516
"Renderer",
1617
"Slider",
18+
"TextEdit",
1719
"Treeform",
1820
"Sceneform",
1921
"ViewModeAction",

src/compas_viewer/components/button.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ def __init__(
2323
parent=None,
2424
):
2525
super().__init__()
26+
2627
if text:
2728
self.setText(text)
2829
if icon_path:
2930
self.setIcon(QtGui.QIcon(set_icon_path(icon_path)))
31+
self.setIconSize(QtCore.QSize(17, 17))
3032
if tooltip:
3133
self.setToolTip(tooltip)
3234
if action:
3335
self.clicked.connect(action)
34-
self.setIconSize(QtCore.QSize(17, 17))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from typing import Callable
2+
from typing import Optional
3+
4+
from PySide6.QtCore import Qt
5+
6+
# from PySide6.QtGui import QDoubleValidator
7+
from PySide6.QtWidgets import QHBoxLayout
8+
from PySide6.QtWidgets import QLabel
9+
from PySide6.QtWidgets import QLineEdit
10+
from PySide6.QtWidgets import QSizePolicy
11+
from PySide6.QtWidgets import QWidget
12+
13+
14+
class LineEdit(QWidget):
15+
"""
16+
A customizable QTextEdit widget for Qt applications, supporting text alignment and font size adjustments.
17+
"""
18+
19+
def __init__(
20+
self,
21+
text: Optional[str] = None,
22+
label: Optional[str] = None,
23+
action: Optional[Callable] = None,
24+
):
25+
super().__init__()
26+
27+
self.action = action
28+
29+
label = QLabel(label)
30+
label.setStyleSheet("""margin-right: 8px;""")
31+
32+
self.text_edit = QLineEdit()
33+
self.text_edit.setMaximumSize(85, 25)
34+
self.text_edit.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
35+
self.text_edit.setText(text)
36+
self.text_edit.setStyleSheet("""padding: 2px;""")
37+
38+
# validator = QDoubleValidator()
39+
40+
self.layout = QHBoxLayout()
41+
self.layout.setSpacing(0)
42+
self.layout.setContentsMargins(0, 0, 0, 0)
43+
self.layout.setAlignment(Qt.AlignLeft)
44+
self.layout.addWidget(label)
45+
self.layout.addWidget(self.text_edit)
46+
self.setLayout(self.layout)
47+
48+
self.text_edit.returnPressed.connect(self.text_update)
49+
50+
def text_update(self):
51+
try:
52+
value = float(self.text_edit.text())
53+
except ValueError:
54+
pass
55+
else:
56+
if self.action:
57+
self.action(self, value)

src/compas_viewer/components/textedit.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,15 @@ def __init__(
1616
):
1717
super().__init__()
1818

19-
self._default_layout = None
20-
2119
self.text_edit = QTextEdit()
2220
self.text_edit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
2321
self.text_edit.setMaximumSize(85, 25)
2422
self.text_edit.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
2523
self.text_edit.setText(text)
2624

27-
self.layout = self.default_layout
25+
self.layout = QHBoxLayout()
26+
self.layout.setSpacing(0)
27+
self.layout.setContentsMargins(0, 0, 0, 0)
2828
self.layout.setAlignment(Qt.AlignCenter)
2929
self.layout.addWidget(self.text_edit)
3030
self.setLayout(self.layout)
31-
32-
@property
33-
def default_layout(self):
34-
if self._default_layout is None:
35-
from compas_viewer.components.layout import DefaultLayout
36-
37-
self._default_layout = DefaultLayout(QHBoxLayout())
38-
return self._default_layout

0 commit comments

Comments
 (0)