Skip to content

StringOrNumberWidget

Qt Base Class: QGroupBox

Signature: QGroupBox(self, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None QGroupBox(self, title: str, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None

Base classes

Name Children Inherits
GroupBox
prettyqt.widgets.groupbox

⋔ Inheritance diagram

graph TD
  1473367119440["custom_widgets.StringOrNumberWidget"]
  1473296374960["widgets.GroupBox"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473290638864["QtWidgets.QGroupBox"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473296374960 --> 1473367119440
  1473293688240 --> 1473296374960
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473290638864 --> 1473296374960
  1473290849680 --> 1473290638864
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: GroupBox

Source code in prettyqt\custom_widgets\editors\stringornumberwidget.py
class StringOrNumberWidget(widgets.GroupBox):
    value_changed = core.Signal(object)

    def __init__(self, *args, object_name: str = "string_or_number_widget", **kwargs):
        super().__init__(*args, object_name=object_name, **kwargs)
        self.set_layout("vertical")
        self.rb_lineedit = widgets.RadioButton("String", checked=True)
        self.lineedit = widgets.LineEdit()
        self.rb_spinbox = widgets.RadioButton("Number")
        self.spinbox = widgets.DoubleSpinBox()
        layout_lineedit = widgets.HBoxLayout()
        layout_lineedit.add(self.rb_lineedit)
        layout_lineedit.add(self.lineedit)
        layout_spinbox = widgets.HBoxLayout()
        layout_spinbox.add(self.rb_spinbox)
        layout_spinbox.add(self.spinbox)
        self.box.add(layout_lineedit)
        self.box.add(layout_spinbox)
        self.rb_spinbox.toggled.connect(self.spinbox.setEnabled)
        self.rb_spinbox.toggled.connect(self.lineedit.setDisabled)
        self.rb_lineedit.toggled.connect(self.lineedit.setEnabled)
        self.rb_lineedit.toggled.connect(self.spinbox.setDisabled)
        self.spinbox.value_changed.connect(self.on_value_change)
        self.lineedit.value_changed.connect(self.on_value_change)

    def on_value_change(self):
        value = self.get_value()
        self.value_changed.emit(value)

    def get_value(self) -> float | str:
        if not self.rb_spinbox.isChecked():
            return self.lineedit.get_value()
        val = self.spinbox.get_value()
        return int(val) if val.is_integer() else val

    def set_value(self, value: float | str):
        match value:
            case str():
                self.rb_lineedit.setChecked(True)
                self.lineedit.set_value(value)
            case int() | float():
                self.rb_spinbox.setChecked(True)
                self.spinbox.set_value(value)
            case _:
                raise TypeError(f"Invalid Type for set_value: {type(value)}")

⌗ Property table

Qt Property Type Doc
objectName QString
modal bool
windowModality Qt::WindowModality
enabled bool
geometry QRect
frameGeometry QRect
normalGeometry QRect
x int
y int
pos QPoint
frameSize QSize
size QSize
width int
height int
rect QRect
childrenRect QRect
childrenRegion QRegion
sizePolicy QSizePolicy
minimumSize QSize
maximumSize QSize
minimumWidth int
minimumHeight int
maximumWidth int
maximumHeight int
sizeIncrement QSize
baseSize QSize
palette QPalette
font QFont
cursor QCursor
mouseTracking bool
tabletTracking bool
isActiveWindow bool
focusPolicy Qt::FocusPolicy
focus bool
contextMenuPolicy Qt::ContextMenuPolicy
updatesEnabled bool
visible bool
minimized bool
maximized bool
fullScreen bool
sizeHint QSize
minimumSizeHint QSize
acceptDrops bool
windowTitle QString
windowIcon QIcon
windowIconText QString
windowOpacity double
windowModified bool
toolTip QString
toolTipDuration int
statusTip QString
whatsThis QString
accessibleName QString
accessibleDescription QString
layoutDirection Qt::LayoutDirection
autoFillBackground bool
styleSheet QString
locale QLocale
windowFilePath QString
inputMethodHints QFlags
title QString
alignment QFlags
flat bool
checkable bool
checked bool