Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Panel
borderStyle
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleStart a new scriptdashed
  • Click File > New > Text Editor

This will create a new empty text editor where the graphics window used to be.

...

No Format
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleCreate a toplevel windowborderStyledashed
set w [qwidget ]

A window in QTcl is an instance of a QWidget object, hence the command name. It may be followed by a list of flags. Although rarely used, the flags can be used to modify the widgets look and behavior. The next statement tells QTcl to delete the widget from memory when it is closed:

No Format
borderStyle
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleSet widget to be deleted from memory when closeddashed
qsetattribute deleteonclose

...

No Format
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleSet window title to "Hello"borderStyledashed
qsetwindowtitle "Hello"

The qsetwindowtitle command sets the window title. While there may be several windows available, QTcl will simply apply the command to the most recently created widget, which in this case is the QWidget window. The most recently created widget is also the so-called current widget. It does not matter whether the widget is visible or not. This is in fact how most Qt commands work.

...

No Format
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleCreate a layoutborderStyledashed
qvboxlayout {

}

The qvboxlayout command creates a layout manager for the window. A layout manager is also known as a geometry manager. The task of the layout manager is to arrange the widgets in a particular order. For instance, the QVBoxLayout layout manager stacks widgets vertically in their order of creation. There are two other layout managers in QTcl:

...

No Format
borderStyle
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleCreate a push buttondashed
qpushbutton "Hello world!"

...

No Format
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleAdd an executing command to the buttonborderStyledashed
qinformation Information "Hello world!"

...

No Format
borderStyle
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleAdd an executing command to the buttondashed
qshow $w

QTcl will then draw the most recently created widget, or current widget, on to the screen. In this case the current widget is the window, which is then displayed along with its contents.

...

No Format
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleFinal scriptborderStyledashed
# Create toplevel window
set w [qwidget ]

# Delete window from memory when closing
qsetattribute deleteonclose

qsetwindowtitle "Hello"

# Arrange contents vertically
qvboxlayout {
	# Create a button that show an information dialog when pushed
	qpushbutton "Hello world!" { qinformation Information "Hello world!" }
}

# Make window visible
qshow $w

Panel
borderColor#404040
bgColor#F0F0F0
borderWidth1
borderStyledashed
titleExecute the scriptborderStyledashed
  • Execute the script by right clicking anywhere in the text editor window and selecting Execute

A window with a Hello world!-button should now appear, and when clicking this button an information window saying "Hello world!" with an OK button should appear.

...