Class: Cosmos::StringChooser

Inherits:
Qt::Widget show all
Defined in:
lib/cosmos/gui/choosers/string_chooser.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent, label_text, initial_value, field_width = 20, fill = false, read_only = false, alignment = Qt::AlignLeft | Qt::AlignVCenter) ⇒ StringChooser

Returns a new instance of StringChooser.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cosmos/gui/choosers/string_chooser.rb', line 17

def initialize(
  parent, label_text, initial_value,
  field_width = 20, fill = false, read_only = false, alignment = Qt::AlignLeft | Qt::AlignVCenter
)
  super(parent)
  layout = Qt::HBoxLayout.new(self)
  layout.setContentsMargins(0,0,0,0)
  @string_label = Qt::Label.new(label_text)
  @string_label.setSizePolicy(Qt::SizePolicy::Fixed, Qt::SizePolicy::Fixed) if fill
  if fill
    layout.addWidget(@string_label)
  else
    layout.addWidget(@string_label, 1)
  end
  layout.addStretch unless fill
  @string_value = Qt::LineEdit.new(initial_value.to_s)
  @string_value.setMinimumWidth(field_width)
  @string_value.setReadOnly(true) if read_only
  @string_value.setAlignment(alignment)
  layout.addWidget(@string_value)
  setLayout(layout)
end

Instance Method Details

#stringObject Also known as: value

Returns the text field as a string



41
42
43
# File 'lib/cosmos/gui/choosers/string_chooser.rb', line 41

def string
  @string_value.text
end

#value=(new_value) ⇒ Object

Sets the value



47
48
49
# File 'lib/cosmos/gui/choosers/string_chooser.rb', line 47

def value=(new_value)
  @string_value.setText(new_value.to_s)
end