On Monday 23 June 2008 16:51:53 Simon Hausmann wrote:
> On Saturday 14 June 2008 10:41:28 [EMAIL PROTECTED] wrote:
> > Hi Trolls,
> > I can't use setHtml member of QWebFrame class. For me is not working
> > (see the output of ->> qDebug()<<page.mainFrame()->toHtml();<<-).
> > I made an example.
> >
> > //test.h
> >
> > #ifndef TEST_H
> > #define TEST_H
> >
> > #include <QWidget>
> > #include <QPaintEvent>
> > #include <QPainter>
> > #include <QWebPage>
> > #include <QWebFrame>
> > #include <QDebug>
> >
> > class Test : public QWidget
> > {
> > Q_OBJECT
> >
> > public:
> > Test(QWidget *parent = 0): QWidget(parent){}
> > protected:
> > void paintEvent(QPaintEvent * event)
> > {
> > QWidget::paintEvent(event);
> > QPainter painter(this);
> > painter.setRenderHint(QPainter::Antialiasing);
> > painter.translate(50,50);
> > painter.drawText(10,10,"Trolltech");
> > painter.translate(100,100);
> > QWebPage page;
> > page.mainFrame()->setHtml("<b>Trolltech</b>");
> > qDebug()<<page.mainFrame()->toHtml();
> > // page.mainFrame()->render(&painter,geometry());
> > page.mainFrame()->render(&painter);
> > }
> > };
> >
> > #endif
> >
> > // main.cpp
> > #include <QApplication>
> > #include "test.h"
> >
> > int main(int argc, char *argv[])
> > {
> > QApplication app(argc, argv);
> > Test t;
> > t.show();
> > return app.exec();
> > }
> >
> > I use qt 4.4.0 (from debian unstable).
>
> Oops, that's a bug. setHtml should set the contents immediately. I've
> attached the patch that fixes this, it will be in Qt 4.4.2.
>
> As a workaround you could call setHtml in the constructor of your class.
> The contents will then be populated into the QWebPage next time the event
> loop spins. That is also much faster than calling setHtml() on every paint
> event, as that parses the HTML every time.Oops, I forgot to mention: The patch fixes only the asymmetry of setHtml, now toHtml() returns the right value right after calling setHtml(). In order for render() to work you also have to layout the page, you have to set a viewport size, so WebKit knows where to break content into multiple lines. In order words: page.setViewportSize(size()); after setHtml() will make the render() call and therefore your example work :) Simon
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Qt4-preview-feedback mailing list [email protected] http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback
