Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
{alias:qtrace}
h2. Name

*qtrace* — connect widget and Tcl variable

h2. Syntax
{panel:|borderStyle=solid|borderWidth=1|bgColor=#FFFFAA}

*qtrace* \[_widget_] _variable_ 

{panel}

h2. Description

The *qtrace* command assigns a trace variable to a widget. A trace variable will at all times reflect the state or contents of the widget to which it is assigned. Writing to the variable will update the widget accordingly. 

{note} 
Assigning a value to a trace-variable may result in the corresponding widgets callback function being called. Use [qblockedtrace] to create a trace variable without this effect. 
{note}  

h2. Arguments

_widget_
{indent}The widget to which the variable will be connected. If this argument is omitted the current widget will be used. This must be an instance of [QLineEdit], [QLabel], [QTextEdit], [QTextEdit, [QCheckBox], [QRadioButton], [QSpinBox], [QDoubleSpinBox], [QHSlider], and [QVSlider]. 
{indent}]

_variable_
{indent}The name of the variable. The variable should be global or exist in a namespace. When referring to a namespace variable the namespace name should be part of the argument, like "MyNamespace::my_variable". 

{indent} 

h2. Examples

h3. Ex.1: QTrace
{anchor:QTrace}

{noformat:|borderWidth=1|bgColor=#eeeeee}
set w [qwidget ]
qsetwindowtitle "Variable tracing"

# Create text editor and "Show Text" button.
set layout [qhboxlayout $w]
set label [qlabel "First Name :"]
qaddwidget $layout $label

set lineedit [qlineedit]
qaddwidget $layout $lineedit

# Connect contents of line edit to variable 'name'
qtrace $lineedit name

# Set Tcl variable - this will automatically set the
# text in the line edit to   'Jon'
set name Jon

qshow $w

{noformat}

The above example attaches the variable 'name' to the lineedit for entering a persons name. Throughout the execution of the program these entities will keep one another automatically updated. When the variable 'name' is assigned the name "Jon", the lineedit is updated accordingly. This can be seen in the screenshot. Also, if the user were to edit the lineedit directly, the 'name' variable would be updated accordingly. 

!att:_img_cmd^qtrace.png!

{pagebreak}