Class WQrCode
- Direct Known Subclasses:
TotpQrCode
This widget allows to generate QR code from a string.
If you wish to alter the look of the QR code (to add a logo in the middle for instance), you
can override paintEvent. However, you will still need to call the paintEvent()
to generate the QR code itself.
The content that is encoded is taken as-is. If the purpose of your QR code requires special formatting, the formatted string needs to be supplied to the constructor.
By default, the generated QR code will use the lowest possible error correction, and a square size of 5 pixels.
Usage example:
String website = "https://webtoolkit.eu";
WApplication app = WApplication.getInstance();
app.getRoot().addWidget(new WQrCode(website));
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Represents the different error correction levels for QR codes.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefault
-
Constructor Summary
ConstructorsConstructorDescriptionWQrCode()
Creates a default QR code with an empty message.WQrCode
(WContainerWidget parentContainer) Creates a default QR code with an empty message.Creates a QR code.Creates a QR code.WQrCode
(String message, double squareSize, WContainerWidget parentContainer) Creates a QR code.WQrCode
(String message, WQrCode.ErrorCorrectionLevel ecl) Creates a QR code.WQrCode
(String message, WQrCode.ErrorCorrectionLevel ecl, double squareSize) Creates a QR code.WQrCode
(String message, WQrCode.ErrorCorrectionLevel ecl, double squareSize, WContainerWidget parentContainer) Creates a QR code. -
Method Summary
Modifier and TypeMethodDescriptiongetBrush()
Returns the brush with which the QR code is painted.Returns the error correction level of the QR code.Returns the message of the QR code.double
Returns the size of the squares composing the QR code.boolean
isError()
Returns whether an error stopped the generation of the QR code.protected void
paintEvent
(WPaintDevice paintDevice) Paints the widget.void
Sets the brush with which the QR code is painted.void
Set the error correction level of the QR code.void
setMessage
(String message) Set the message of the QR code.void
setSquareSize
(double size) Set the size of the dots composing the QR code.Methods inherited from class eu.webtoolkit.jwt.WPaintedWidget
addArea, createDomElement, createJSBrush, createJSPainterPath, createJSPen, createJSPoint, createJSRect, createJSTransform, enableAjax, getArea, getAreas, getCreatePaintDevice, getDomChanges, getMethod, getObjJsRef, getPreferredMethod, getRepaintSlot, insertArea, layoutSizeChanged, refresh, remove, removeArea, render, resize, setFormData, setPreferredMethod, update, update, update
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, iterateChildren, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, removeWidget, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
Methods inherited from class eu.webtoolkit.jwt.WObject
getObjectName
-
Constructor Details
-
WQrCode
Creates a default QR code with an empty message. -
WQrCode
public WQrCode()Creates a default QR code with an empty message. -
WQrCode
Creates a QR code.Create a QR code with the given message, and square size.
-
WQrCode
Creates a QR code. -
WQrCode
public WQrCode(String message, WQrCode.ErrorCorrectionLevel ecl, double squareSize, WContainerWidget parentContainer) Creates a QR code.Create a QR code with the given message, error correction level and square size.
-
WQrCode
Creates a QR code.Calls
this(message, WQrCode.ErrorCorrectionLevel.LOW, 5.0, (WContainerWidget)null)
-
WQrCode
Creates a QR code. -
WQrCode
Creates a QR code.Calls
this(message, ecl, squareSize, (WContainerWidget)null)
-
-
Method Details
-
setErrorCorrectionLevel
Set the error correction level of the QR code.Increases the amount of information that can be lost before altering the encoded message. A higher level of error correcting code, makes the QR code more robust to changes.
Increasing the error correction level also increases the amount of data needed to encode the message, resulting in a visually bigger QR code than one with a lower error correcting level.
By default,
LOW
is used.- See Also:
-
getErrorCorrectionLevel
Returns the error correction level of the QR code. -
setMessage
Set the message of the QR code.This sets the message carried by the QR code. There is a limit to the size of the message which depends on many factors. The most important one is the error correction level. Higher error correction level diminish the maximum size the message can have. Roughly speaking when using the highest level of error correction, the maximum number of allowed content is in the area of 1Kb, whereas for the lowest level of error correction, this is around 3Kb.
The longer the message is, the more data needs to be encoded, and thus the bigger the resulting QR code becomes.
If the message is to long, the QR code will not be generated.
-
getMessage
Returns the message of the QR code.- See Also:
-
setSquareSize
public void setSquareSize(double size) Set the size of the dots composing the QR code.Sets the size (in pixels) that each dot of the QR code will have. A single square of the QR code can be seen in any corner of the QR code. There a reference visual is always displayed that contains exactly seven dots in width and height.
This allows the application to correctly resize the QR code.
-
getSquareSize
public double getSquareSize()Returns the size of the squares composing the QR code.- See Also:
-
isError
public boolean isError()Returns whether an error stopped the generation of the QR code.Returns true if the QR code could not be generated due to an error.
In case the QR code was not generated, it's size will be set to 0 and the QR code will not be painted.
-
setBrush
Sets the brush with which the QR code is painted.This allows for the color of the QR code to be changed.
-
getBrush
Returns the brush with which the QR code is painted.- See Also:
-
paintEvent
Description copied from class:WPaintedWidget
Paints the widget.You should reimplement this method to paint the contents of the widget, using the given paintDevice.
- Specified by:
paintEvent
in classWPaintedWidget
-