A painted widget is rendered from basic drawing primitives. Rendering is done not on the server but on the browser, using different rendering methods:html
【WPaintedWidget渲染自基本的繪圖元素,渲染髮生在瀏覽器端,而不是服務器端,可能採用如下渲染方法:】c++
Browser | Methods | Default method |
Firefox 1.5+ | HtmlCanvas, InlineSVG | HtmlCanvas |
Internet Explorer 6.0+ | InlineVML | InlineVML |
Safari | HtmlCanvas, InlineSVG | HtmlCanvas |
Opera | InlineSVG, HtmlCanvas* | InlineSVG |
other | ? | HtmlCanvas |
* HtmlCanvas occasionally suffers from rendering artefacts in Opera.web
The different rendering methods correspond to different WPaintDevice implementations, from which this widget choses a suitable one depending on the browser capabilities and configuration.瀏覽器
【不一樣的渲染方法對應不一樣的 WPaintDevice 實現,WPaintedWidget 會根據瀏覽器能力和配置自動選擇適合的渲染方法。 】服務器
If no JavaScript is available, the JavaScript-based HtmlCanvas will not be used, and InlineSVG will be used instead. The method used may be changed by using setPreferredMethod().app
【若是禁用 JavaScript, 那麼基於 JavaScript 的 HtmlCanvas 將不會被採用,而使用 InlineSVG 代替。咱們能夠使用 setPreferredMethod() 方法改變渲染方法。 】ide
InlineSVG requires that the document is rendered as XHTML. This must be enabled in the configuration file using the <send-xhtml-mime-type>
option. By default, this option is off.佈局
【InlineSVG 須要 文檔做爲 XHTML 渲染,這就要求配置文件中必須設置 <send-xhtml-mime-type>
選項,默認狀況下,這個選項是被關閉的。 】ui
To use a WPaintedWidget, you must derive from it and reimplement paintEvent(WPaintDevice *paintDevice). To paint on a WPaintDevice, you will need to use a WPainter. Repainting is triggered by calling the update() method.this
【要想使用 WPaintedWidget,你必須定義繼承於它的子類,並從新實現 paintEvent(WPaintDevice *paintDevice) 。要想在 WPaintDevice 做畫,你須要使用 WPainter 。Repainting 是由 update() 引起的。 】
Usage example:【示例】
class MyPaintedWidget : public Wt::WPaintedWidget
{
public:
MyPaintedWidget(Wt::WContainerWidget *parent = 0)
: Wt::WPaintedWidget(parent),
foo_(100)
{
resize(200, 200); // provide a default size
}
void setFoo(int foo) {
foo_ = foo;
update(); // trigger a repaint
}
protected:
void paintEvent(Wt::WPaintDevice *paintDevice) {
Wt::WPainter painter(paintDevice);
painter.drawLine(20, 20, foo_, foo_);
...
}
private:
int foo_;
};
Styling through CSS is not applicable.