Checkbox And Radio Widget
Neither platform's chart object set has a checkbox or a radio button - both are conventionally faked with OBJ_BUTTON and some way of showing which state it is in. The obvious way, a symbol-font glyph such as a Wingdings checkmark, depends on the font actually being installed and mapped the way the author's machine had it; a CodeBase download runs on whatever the downloader's Windows happens to have, and a missing glyph typically renders as an empty box rather than failing loudly. This header uses plain text instead - "[X] "/"[ ] " for the checkbox, "(*) "/"( ) " for a radio option - prepended to the label, which renders identically everywhere a font can draw ASCII text at all. CCheckboxWidget is a single independent toggle: Clicked() flips IsChecked() and redraws the mark, and a disabled checkbox reports no clicks at all rather than requiring the caller to guard every click site. CRadioGroup manages a set of mutually exclusive options as a single unit. It is deliberately not built from several CCheckboxWidget instances - MQL4 arrays of class instances carry constructor and destructor bookkeeping this problem does not need, and the same shape was kept on the MQL5 side for consistency between the two sources. Instead the group tracks its options as parallel arrays of name, id and label, the same pattern this catalogue's PanelFramework library uses for its own children, and creates its objects directly. Clicking any option in the group deselects whichever option was previously selected and redraws both, so exactly one option is ever marked selected at a time. Re-clicking the option already selected keeps it selected - conventional radio behaviour never lets a click clear the whole group down to nothing chosen. Notes and limitations - The demo cannot generate a real mouse click, since a script's OnStart runs once with no live event loop. It calls Clicked() directly with each control's own object name, the same call a host program's OnChartEvent would make on a genuine click. - The check mark is plain bracket text, not a checkbox-shaped drawing. It reads clearly in the terminal's default font but will not match a custom themed panel pixel-for-pixel the way a bitmap checkbox would. - CRadioGroup enforces exclusivity only among options added to the same instance. Two separate CRadioGroup instances on the same chart do not know about each other and can both show a selection at once, by design - that is how two independent radio groups are meant to behave. - Neither widget depends on PanelFramework, ChartObjects or WidgetButton in this catalogue; combine them by object-name prefix convention if a panel needs several widget types together.
Script · MT4 · v1.0 · Free
About Checkbox And Radio Widget
Checkbox And Radio Widget is a script for MetaTrader 4. It has 1 setting, such as Prefix. MQL source code included.
Files in the download: WidgetChoice.mqh, WidgetChoice.txt, WidgetChoiceDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Prefix | WidgetChoiceDemo_ | Object-name prefix for this demo's controls |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT4 Script · MQL4 Source Code