Archive for the ‘C++/Qt’ Category

QtWebKit – turn javascript and images off

Thursday, June 18th, 2009

How to turn javascript and images off in QWebView?

QWebView *myWebView = new QWebView(this);
....
myWebView->settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
myWebView->settings()->setAttribute(QWebSettings::AutoLoadImages, false);

That’s all :)

QWhatsThis – fighting with wordwrap

Saturday, June 13th, 2009

Another problem with QWhatsThis::showText() method: word wrapping. If you want to turn it off, you’d probably face with some problems: it’s not as easy as it supposed to be.

I’ve found the solution that satisfied me: instead of calling

QWhatsThis::showText(myPoint, "blah blah...", ...);

I frame “blah blah …” text into table with <nobr> tags and use this call:

QWhatsThis::showText(myPoint, "<table><tr><td><nobr>blah blah...</nobr></td></tr></table>", ...);

This solved my problems.

Qt: QWhatsThis – handling clicks

Saturday, June 13th, 2009

QWhatsThis::showText() shows beautiful hint where one can place HTML formatted text. The question is: how we can handle link clicks, like <a href=”more”>more…</a>?

The answer is located in this thread: one should re-implement QWidget::event() method for “parent” widget (3rd param in QWhatsThis::showText() method), like:

void MyWidget::event(QEvent *_event)
{
    if (_event->type() == QEvent::WhatsThisClicked){
        if (QWhatsThisClickedEvent* clicked = dynamic_cast(_event)){
            QString href = clicked->url(); // here is the "href" value of the link user clicked
            ...........
        }
    }
    return QWidget::event(_event);
}

So, when user clicks on the <a href> link, MyWidget::event() fires, extracts the “url” and handles it.

If you don’t want to re-implement the QWidget::event() method, you could use installEventFilter().