Project

General

Profile

WPainter unable to draw an image

Added by Alan Finley about 11 years ago

I'm using Wt 3.2.3 and trying to create a simple painter that draws an image as it's described in this painting example.

My code:

void paintEvent(Wt::WPaintDevice *paintDevice)

{

@ Wt::WPainter painter(paintDevice);@

@ Wt::WPainter::Image image("icons/sp.jpg", 639, 354);@

@ painter.drawImage(0.0, 0.0, image);@

}

But the painter draws nothing.

I used Google Chrome Developer Tools to get some logs.

I can see that the image is actually loaded.

But there is an 'Uncaught TypeError' error in this js function:

if(Wt3_2_3.getElement('cobmmwsj').getContext){new Wt._p_.ImagePreloader(['icons/sp.jpg'...


Replies (7)

RE: WPainter unable to draw an image - Added by Wim Dumon about 11 years ago

Hi Alan,

I can't reproduce this on the current git version... Do you have any extra information on this bug? Does it work with latest git? Does the problem only exist with chrome or also on other browsers?

BR,

Wim.

RE: WPainter unable to draw an image - Added by Alan Finley about 11 years ago

It doen't work with the latest git version too.

Now I get 'Uncaught SyntaxError: Unexpected token +' on this line:

if(Wt3_3_0.getElement('col4idsf').getContext){new Wt._p_.ImagePreloader(['/icons/sp.jpg']...

It doesn't work on any browser.

RE: WPainter unable to draw an image - Added by Wim Dumon about 11 years ago

Can you provide a full example that demonstrates the error?

Also, developer tools let you format the JS output when you click the '{}' icon, you'll get a better indication on what exactly is wrong.

Wim.

RE: WPainter unable to draw an image - Added by Alan Finley about 11 years ago

I don't know js good enough to get what is wrong by reading the sources.

Here's my full code:

class ImagePainter : public Wt::WPaintedWidget
{
public:
    ImagePainter(Wt::WContainerWidget *parent = 0);

protected:
    void paintEvent(Wt::WPaintDevice *paintDevice);
};

ImagePainter::ImagePainter(Wt::WContainerWidget *parent)
    : WPaintedWidget(parent)
{
    resize(400, 400);

    Wt::WCssDecorationStyle style = decorationStyle();
    style.setBorder(Wt::WBorder(Wt::WBorder::Solid, 4, Wt::red));
    setDecorationStyle(style);
}

void
ImagePainter::paintEvent(WPaintDevice *paintDevice)
{
    Wt::WPainter painter(paintDevice);
    Wt::WPainter::Image image("icons/sp.jpg", 199, 253);
    painter.drawImage(0.0, 0.0, image);
}

Wt::WApplication*
createApplication(const Wt::WEnvironment& env)
{
    Wt::WApplication *app = new Wt::WApplication(env);

    ImagePainter *p = new ImagePainter(app->root());

    return app;
}

int
main(int argc, char **argv)
{
    return WRun(argc, argv, &createApplication);
}

RE: WPainter unable to draw an image - Added by Wim Dumon about 11 years ago

I cannot reproduce this, it works for me.

Please let Chrome developer tools format the JS and look at the line where the JS error is. If you don't see it, copy-paste about 10 lines (that include the error) here so that we can take a look at it.

BR,

Wim.

RE: WPainter unable to draw an image - Added by Alan Finley about 11 years ago

Here is the code:

if (Wt3_3_0.getElement('cou39vwg').getContext) {
new Wt._p_.ImagePreloader(['/icons/sp.jpg'], function(images) {
    var ctx = Wt3_3_0.getElement('cou39vwg').getContext('2d');
    ctx.clearRect(0, 0, 400, 400);
    ctx.save();
    ctx.save();
    ctx.lineWidth = 1;
    ctx.lineCap = 'square';
    ctx.font = '10.0pt sans-serif ';
    ctx.drawImage(images[0], 0, 0000000e+00, 0, 0000000e+00, 1, 9900000e+02, 2, 5300000e+02, 0, 0000000e+00, 0, 0000000e+00, 1, 9900000e+02, 2, 5300000e+02);
    ctx.restore();
    ctx.restore();
});
}

RE: WPainter unable to draw an image - Added by Alan Finley about 11 years ago

Sorry, that was my mistake.

I tried to build my app with some Qt objects.

I created a QCoreApplication object in the main function. So I removed it, and everything is ok now.

    (1-7/7)